Repository navigation
Expand file tree
/
Copy pathlocal-schema.sql
More file actions
2140 lines (2054 loc) · 96.7 KB
/
Copy pathlocal-schema.sql
File metadata and controls
2140 lines (2054 loc) · 96.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- This file is generated by scripts/generate-clickhouse-schema-sql.ts
-- Do not edit manually. Run `bun run clickhouse:schema` to regenerate.
-- projectRevision: 6c40bbce25f0440e6c3d83eb54307565485620b46787fc993b312a1e1ed75f8a
-- localSchemaVersion: 28
CREATE TABLE IF NOT EXISTS ai_crawler_requests (
OrgId LowCardinality(String),
Timestamp DateTime64(9),
TraceId String,
ServiceName LowCardinality(String),
Crawler LowCardinality(String),
Host LowCardinality(String),
Path String,
HttpStatus UInt16
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, Timestamp, TraceId)
TTL toDate(Timestamp) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS ai_trace_index (
OrgId LowCardinality(String),
Timestamp DateTime64(9),
TraceId String,
SessionId String,
VendorId LowCardinality(String),
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
Model LowCardinality(String),
AgentName LowCardinality(String),
ToolName LowCardinality(String),
SpanId String,
ParentSpanId String,
Duration UInt64,
IsError UInt8,
IsLlmCall UInt8,
IsToolCall UInt8,
Tokens Float64,
Cost Float64,
ResponseId String,
VendorVersion LowCardinality(String),
InputTokens Float64,
CacheReadTokens Float64,
CacheWriteTokens Float64,
OutputTokens Float64,
ReasoningTokens Float64,
ErrorType LowCardinality(String),
StatusMessage String,
ToolDescription String,
FailedToolCallResult String,
ErrorFingerprint UInt64
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, Timestamp, TraceId)
TTL toDate(Timestamp) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS alert_checks (
OrgId LowCardinality(String),
RuleId String,
GroupKey String,
Timestamp DateTime64(3),
Status LowCardinality(String),
SignalType LowCardinality(String),
Comparator LowCardinality(String),
Threshold Float64,
ObservedValue Nullable(Float64),
SampleCount UInt32,
WindowMinutes UInt16,
WindowStart DateTime64(3),
WindowEnd DateTime64(3),
ConsecutiveBreaches UInt16,
ConsecutiveHealthy UInt16,
IncidentId Nullable(String),
IncidentTransition LowCardinality(String),
EvaluationDurationMs UInt32,
ErrorMessage Nullable(String),
ErrorCategory LowCardinality(String),
SkipReason LowCardinality(String) DEFAULT ''
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, RuleId, GroupKey, Timestamp)
TTL toDate(Timestamp) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS attribute_keys_hourly (
OrgId LowCardinality(String),
Hour DateTime,
AttributeKey LowCardinality(String),
AttributeScope LowCardinality(String),
UsageCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, AttributeScope, Hour, AttributeKey)
TTL Hour + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS attribute_values_hourly (
OrgId LowCardinality(String),
Hour DateTime,
AttributeKey LowCardinality(String),
AttributeValue String,
AttributeScope LowCardinality(String),
UsageCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, AttributeScope, AttributeKey, Hour, AttributeValue)
TTL Hour + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS audit_log (
OrgId LowCardinality(String),
Id String,
OccurredAt DateTime64(3),
RecordedAt DateTime64(3),
ActorType LowCardinality(String),
UserId String,
ApiKeyId String,
ActorId String,
ActorLabel String,
AffectedUserId String,
Source LowCardinality(String),
Action LowCardinality(String),
Outcome LowCardinality(String),
DenialReason String,
ResourceType LowCardinality(String),
ResourceId String,
ChangedFields Array(String),
Changes String,
Metadata String,
RequestId String,
OriginIp String,
OriginCountry LowCardinality(String)
)
ENGINE = ReplacingMergeTree
PARTITION BY toYYYYMM(OccurredAt)
ORDER BY (OrgId, OccurredAt, Id)
TTL toDate(OccurredAt) + INTERVAL 2190 DAY;
CREATE TABLE IF NOT EXISTS error_events (
OrgId LowCardinality(String),
Timestamp DateTime,
TraceId String,
SpanId String,
ParentSpanId String DEFAULT '__unset__',
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
ExceptionType LowCardinality(String),
ExceptionMessage String,
ExceptionStacktrace String,
TopFrame String,
FingerprintHash UInt64,
StatusMessage String,
Duration UInt64,
ErrorLabel String,
ServiceVersion LowCardinality(String)
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, FingerprintHash, Timestamp)
TTL Timestamp + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS error_events_by_time (
OrgId LowCardinality(String),
Timestamp DateTime,
TraceId String,
SpanId String,
ParentSpanId String DEFAULT '__unset__',
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
ExceptionType LowCardinality(String),
ExceptionMessage String,
ExceptionStacktrace String,
TopFrame String,
FingerprintHash UInt64,
StatusMessage String,
Duration UInt64,
ErrorLabel String,
ServiceVersion LowCardinality(String)
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, Timestamp, FingerprintHash)
TTL Timestamp + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS error_fingerprints_minutely (
OrgId LowCardinality(String),
Minute DateTime,
FingerprintHash UInt64,
ServiceName SimpleAggregateFunction(anyLast, String),
ExceptionType SimpleAggregateFunction(anyLast, String),
ExceptionMessage SimpleAggregateFunction(anyLast, String),
ErrorLabel SimpleAggregateFunction(anyLast, String),
TopFrame SimpleAggregateFunction(anyLast, String),
OccurrenceCount SimpleAggregateFunction(sum, UInt64),
FirstSeen SimpleAggregateFunction(min, DateTime),
LastSeen SimpleAggregateFunction(max, DateTime),
ServiceVersions SimpleAggregateFunction(groupUniqArrayArray, Array(String))
)
ENGINE = AggregatingMergeTree
PARTITION BY toYYYYMM(Minute)
ORDER BY (OrgId, Minute, FingerprintHash)
TTL Minute + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS identity_links (
OrgId LowCardinality(String),
VisitorId String,
UserId String,
FirstSeen SimpleAggregateFunction(min, DateTime64(9))
)
ENGINE = AggregatingMergeTree
PARTITION BY tuple()
ORDER BY (OrgId, VisitorId, UserId)
TTL toDate(FirstSeen) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS logs (
OrgId LowCardinality(String),
Timestamp DateTime64(9),
TimestampTime DateTime,
TraceId String,
SpanId String,
TraceFlags UInt8,
SeverityText LowCardinality(String),
SeverityNumber UInt8,
ServiceName LowCardinality(String),
Body String,
ResourceSchemaUrl String,
ResourceAttributes Map(LowCardinality(String), String),
ScopeSchemaUrl String,
ScopeName String,
ScopeVersion String,
ScopeAttributes Map(LowCardinality(String), String),
LogAttributes Map(LowCardinality(String), String),
ResourceAttributeItems Array(String) DEFAULT arrayMap((k, v) -> concat(k, char(31), v), mapKeys(ResourceAttributes), mapValues(ResourceAttributes)),
ScopeAttributeItems Array(String) DEFAULT arrayMap((k, v) -> concat(k, char(31), v), mapKeys(ScopeAttributes), mapValues(ScopeAttributes)),
LogAttributeItems Array(String) DEFAULT arrayMap((k, v) -> concat(k, char(31), v), mapKeys(LogAttributes), mapValues(LogAttributes)),
INDEX idx_trace_id TraceId TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_attr_keys mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_attr_vals mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_scope_attr_keys mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_scope_attr_vals mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_log_attr_keys mapKeys(LogAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_log_attr_vals mapValues(LogAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_lower_body lower(Body) TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 8
)
ENGINE = MergeTree
PARTITION BY toDate(TimestampTime)
ORDER BY (OrgId, toStartOfFiveMinutes(Timestamp), ServiceName, Timestamp)
TTL toDate(TimestampTime) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS logs_aggregates_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
SeverityText LowCardinality(String),
DeploymentEnv LowCardinality(String),
Count SimpleAggregateFunction(sum, UInt64),
SizeBytes SimpleAggregateFunction(sum, UInt64),
ServiceNamespace LowCardinality(String),
INDEX idx_service_namespace ServiceNamespace TYPE set(1000) GRANULARITY 4
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, ServiceName, SeverityText, DeploymentEnv, ServiceNamespace)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS metric_catalog (
OrgId LowCardinality(String),
Hour DateTime,
MetricType LowCardinality(String),
ServiceName LowCardinality(String),
MetricName LowCardinality(String),
MetricDescription SimpleAggregateFunction(anyLast, String),
MetricUnit SimpleAggregateFunction(anyLast, String),
IsMonotonic SimpleAggregateFunction(anyLast, UInt8),
DataPointCount SimpleAggregateFunction(sum, UInt64),
FirstSeen SimpleAggregateFunction(min, DateTime),
LastSeen SimpleAggregateFunction(max, DateTime)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, MetricType, ServiceName, MetricName, Hour)
TTL Hour + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS metrics_exponential_histogram (
OrgId LowCardinality(String),
ResourceAttributes Map(LowCardinality(String), String),
ResourceSchemaUrl String,
ScopeName String,
ScopeVersion String,
ScopeAttributes Map(LowCardinality(String), String),
ScopeSchemaUrl String,
ServiceName LowCardinality(String),
MetricName LowCardinality(String),
MetricDescription LowCardinality(String),
MetricUnit LowCardinality(String),
Attributes Map(LowCardinality(String), String),
StartTimeUnix DateTime64(9),
TimeUnix DateTime64(9),
Count UInt64,
Sum Float64,
Scale Int32,
ZeroCount UInt64,
PositiveOffset Int32,
PositiveBucketCounts Array(UInt64),
NegativeOffset Int32,
NegativeBucketCounts Array(UInt64),
ExemplarsTraceId Array(String),
ExemplarsSpanId Array(String),
ExemplarsTimestamp Array(DateTime64(9)),
ExemplarsValue Array(Float64),
ExemplarsFilteredAttributes Array(Map(LowCardinality(String), String)),
Flags UInt32,
Min Nullable(Float64),
Max Nullable(Float64),
AggregationTemporality Int32
)
ENGINE = MergeTree
PARTITION BY toDate(TimeUnix)
ORDER BY (OrgId, ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix))
TTL toDate(TimeUnix) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS metrics_gauge (
OrgId LowCardinality(String),
ResourceAttributes Map(LowCardinality(String), String),
ResourceSchemaUrl String,
ScopeName String,
ScopeVersion String,
ScopeAttributes Map(LowCardinality(String), String),
ScopeSchemaUrl String,
ServiceName LowCardinality(String),
MetricName LowCardinality(String),
MetricDescription LowCardinality(String),
MetricUnit LowCardinality(String),
Attributes Map(LowCardinality(String), String),
StartTimeUnix DateTime64(9),
TimeUnix DateTime64(9),
Value Float64,
Flags UInt32,
ExemplarsTraceId Array(String),
ExemplarsSpanId Array(String),
ExemplarsTimestamp Array(DateTime64(9)),
ExemplarsValue Array(Float64),
ExemplarsFilteredAttributes Array(Map(LowCardinality(String), String))
)
ENGINE = MergeTree
PARTITION BY toDate(TimeUnix)
ORDER BY (OrgId, ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix))
TTL toDate(TimeUnix) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS metrics_histogram (
OrgId LowCardinality(String),
ResourceAttributes Map(LowCardinality(String), String),
ResourceSchemaUrl String,
ScopeName String,
ScopeVersion String,
ScopeAttributes Map(LowCardinality(String), String),
ScopeSchemaUrl String,
ServiceName LowCardinality(String),
MetricName LowCardinality(String),
MetricDescription LowCardinality(String),
MetricUnit LowCardinality(String),
Attributes Map(LowCardinality(String), String),
StartTimeUnix DateTime64(9),
TimeUnix DateTime64(9),
Count UInt64,
Sum Float64,
BucketCounts Array(UInt64),
ExplicitBounds Array(Float64),
ExemplarsTraceId Array(String),
ExemplarsSpanId Array(String),
ExemplarsTimestamp Array(DateTime64(9)),
ExemplarsValue Array(Float64),
ExemplarsFilteredAttributes Array(Map(LowCardinality(String), String)),
Flags UInt32,
Min Nullable(Float64),
Max Nullable(Float64),
AggregationTemporality Int32
)
ENGINE = MergeTree
PARTITION BY toDate(TimeUnix)
ORDER BY (OrgId, ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix))
TTL toDate(TimeUnix) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS metrics_sum (
OrgId LowCardinality(String),
ResourceAttributes Map(LowCardinality(String), String),
ResourceSchemaUrl String,
ScopeName String,
ScopeVersion String,
ScopeAttributes Map(LowCardinality(String), String),
ScopeSchemaUrl String,
ServiceName LowCardinality(String),
MetricName LowCardinality(String),
MetricDescription LowCardinality(String),
MetricUnit LowCardinality(String),
Attributes Map(LowCardinality(String), String),
StartTimeUnix DateTime64(9),
TimeUnix DateTime64(9),
Value Float64,
Flags UInt32,
ExemplarsTraceId Array(String),
ExemplarsSpanId Array(String),
ExemplarsTimestamp Array(DateTime64(9)),
ExemplarsValue Array(Float64),
ExemplarsFilteredAttributes Array(Map(LowCardinality(String), String)),
AggregationTemporality Int32,
IsMonotonic Bool
)
ENGINE = MergeTree
PARTITION BY toDate(TimeUnix)
ORDER BY (OrgId, ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix))
TTL toDate(TimeUnix) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS product_events (
OrgId LowCardinality(String),
Timestamp DateTime64(9),
Source LowCardinality(String) DEFAULT 'browser',
SessionId String DEFAULT '',
Seq UInt32 DEFAULT 0,
VisitorId String DEFAULT '',
UserId String DEFAULT '',
GroupId String DEFAULT '',
Kind LowCardinality(String),
EventName String,
Host LowCardinality(String) DEFAULT '',
PagePath String DEFAULT '',
Url String DEFAULT '',
ServiceName LowCardinality(String) DEFAULT '',
Attributes Map(String, String) DEFAULT map(),
TraceId String DEFAULT '',
SpanId String DEFAULT '',
INDEX idx_event_name EventName TYPE set(64) GRANULARITY 4,
INDEX idx_user_id UserId TYPE bloom_filter GRANULARITY 4,
INDEX idx_trace_id TraceId TYPE bloom_filter GRANULARITY 4
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, Timestamp, VisitorId, SessionId, Seq)
TTL toDate(Timestamp) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_address_resolutions_hourly (
OrgId LowCardinality(String),
Hour DateTime,
SourceService LowCardinality(String),
ParentServerAddress String,
ResolvedTargetService LowCardinality(String),
DeploymentEnv LowCardinality(String)
)
ENGINE = ReplacingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, DeploymentEnv, SourceService, ParentServerAddress, ResolvedTargetService)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_external_edges_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
TargetType LowCardinality(String),
TargetSystem LowCardinality(String),
TargetName String,
DeploymentEnv LowCardinality(String),
CallCount SimpleAggregateFunction(sum, UInt64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
DurationSumMs SimpleAggregateFunction(sum, Float64),
MaxDurationMs SimpleAggregateFunction(max, Float64),
SampleRateSum SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigestWeighted(0.5, 0.95), UInt64, UInt32)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, DeploymentEnv, ServiceName, TargetType, TargetSystem, TargetName)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_map_children (
OrgId LowCardinality(String),
Timestamp DateTime,
TraceId String,
ParentSpanId String,
ServiceName LowCardinality(String),
SpanKind LowCardinality(String),
Duration UInt64,
StatusCode LowCardinality(String),
TraceState String,
DeploymentEnv LowCardinality(String)
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, TraceId, ParentSpanId, Timestamp)
TTL Timestamp + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS service_map_db_edges_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
DbSystem LowCardinality(String),
DeploymentEnv LowCardinality(String),
CallCount SimpleAggregateFunction(sum, UInt64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
DurationSumMs SimpleAggregateFunction(sum, Float64),
MaxDurationMs SimpleAggregateFunction(max, Float64),
SampledSpanCount SimpleAggregateFunction(sum, UInt64),
UnsampledSpanCount SimpleAggregateFunction(sum, UInt64),
SampleRateSum SimpleAggregateFunction(sum, Float64),
DbNamespace LowCardinality(String),
DurationQuantiles AggregateFunction(quantilesTDigestWeighted(0.5, 0.95), UInt64, UInt32)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, DeploymentEnv, ServiceName, DbSystem, DbNamespace)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_map_db_query_shapes_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
DbSystem LowCardinality(String),
DeploymentEnv LowCardinality(String),
QueryKey String,
QueryLabel SimpleAggregateFunction(any, String),
SampleStatement SimpleAggregateFunction(any, String),
CallCount SimpleAggregateFunction(sum, UInt64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
EstimatedCount SimpleAggregateFunction(sum, Float64),
EstimatedErrorCount SimpleAggregateFunction(sum, Float64),
WeightedDurationSumMs SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigestWeighted(0.5, 0.95), UInt64, UInt32),
DbNamespace LowCardinality(String)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, DeploymentEnv, ServiceName, DbSystem, DbNamespace, QueryKey)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_map_edges_hourly (
OrgId LowCardinality(String),
Hour DateTime,
SourceService LowCardinality(String),
TargetService String,
DeploymentEnv LowCardinality(String),
CallCount SimpleAggregateFunction(sum, UInt64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
DurationSumMs SimpleAggregateFunction(sum, Float64),
MaxDurationMs SimpleAggregateFunction(max, Float64),
SampledSpanCount SimpleAggregateFunction(sum, UInt64),
UnsampledSpanCount SimpleAggregateFunction(sum, UInt64),
SampleRateSum SimpleAggregateFunction(sum, Float64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, DeploymentEnv, SourceService, TargetService)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_map_edges_hourly_ingest (
OrgId LowCardinality(String),
Hour DateTime,
SourceService LowCardinality(String),
TargetService String,
DeploymentEnv LowCardinality(String),
CallCount UInt64,
ErrorCount UInt64,
DurationSumMs Float64,
MaxDurationMs Float64,
SampledSpanCount UInt64,
UnsampledSpanCount UInt64,
SampleRateSum Float64
)
ENGINE = Null;
CREATE TABLE IF NOT EXISTS service_map_spans (
OrgId LowCardinality(String),
Timestamp DateTime,
TraceId String,
SpanId String,
ParentSpanId String,
ServiceName LowCardinality(String),
SpanKind LowCardinality(String),
Duration UInt64,
StatusCode LowCardinality(String),
TraceState String,
DeploymentEnv LowCardinality(String)
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, TraceId, SpanId, Timestamp)
TTL Timestamp + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS service_operations_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
SpanName String,
SpanCount SimpleAggregateFunction(sum, UInt64),
EstimatedSpanCount SimpleAggregateFunction(sum, Float64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
EstimatedErrorCount SimpleAggregateFunction(sum, Float64),
DurationSum SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigest(0.5, 0.95), UInt64),
ClassifiedSpanCount SimpleAggregateFunction(sum, UInt64),
ServerSpanCount SimpleAggregateFunction(sum, UInt64),
RoutedSpanCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toYYYYMM(Hour)
ORDER BY (OrgId, ServiceName, DeploymentEnv, Hour, SpanName)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_operations_minutely (
OrgId LowCardinality(String),
Minute DateTime,
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
SpanName String,
SpanCount SimpleAggregateFunction(sum, UInt64),
EstimatedSpanCount SimpleAggregateFunction(sum, Float64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
EstimatedErrorCount SimpleAggregateFunction(sum, Float64),
DurationSum SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigest(0.5, 0.95), UInt64),
ClassifiedSpanCount SimpleAggregateFunction(sum, UInt64),
ServerSpanCount SimpleAggregateFunction(sum, UInt64),
RoutedSpanCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Minute)
ORDER BY (OrgId, ServiceName, DeploymentEnv, Minute, SpanName)
TTL toDate(Minute) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS service_overview_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
ServiceNamespace LowCardinality(String),
CommitSha LowCardinality(String),
SpanCount SimpleAggregateFunction(sum, UInt64),
EstimatedSpanCount SimpleAggregateFunction(sum, Float64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
EstimatedErrorCount SimpleAggregateFunction(sum, Float64),
DurationSum SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigest(0.5, 0.95, 0.99), UInt64),
FirstSeen SimpleAggregateFunction(min, DateTime),
ApdexSatisfiedCount SimpleAggregateFunction(sum, UInt64),
ApdexToleratingCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toYYYYMM(Hour)
ORDER BY (OrgId, ServiceName, Hour, DeploymentEnv, ServiceNamespace, CommitSha)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_overview_minutely (
OrgId LowCardinality(String),
Minute DateTime,
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
ServiceNamespace LowCardinality(String),
CommitSha LowCardinality(String),
SpanCount SimpleAggregateFunction(sum, UInt64),
EstimatedSpanCount SimpleAggregateFunction(sum, Float64),
ErrorCount SimpleAggregateFunction(sum, UInt64),
EstimatedErrorCount SimpleAggregateFunction(sum, Float64),
DurationSum SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigest(0.5, 0.95, 0.99), UInt64),
FirstSeen SimpleAggregateFunction(min, DateTime),
ApdexSatisfiedCount SimpleAggregateFunction(sum, UInt64),
ApdexToleratingCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Minute)
ORDER BY (OrgId, ServiceName, Minute, DeploymentEnv, ServiceNamespace, CommitSha)
TTL toDate(Minute) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS service_overview_spans (
OrgId LowCardinality(String),
Timestamp DateTime,
ServiceName LowCardinality(String),
Duration UInt64,
StatusCode LowCardinality(String),
TraceState String,
DeploymentEnv LowCardinality(String),
CommitSha LowCardinality(String),
SampleRate Float64 DEFAULT 1,
ServiceNamespace LowCardinality(String),
SpanKind LowCardinality(String) DEFAULT '',
IsRoot UInt8 DEFAULT 0,
INDEX idx_service_namespace ServiceNamespace TYPE set(1000) GRANULARITY 4
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, ServiceName, Timestamp)
TTL Timestamp + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS service_platforms_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
DeploymentEnv LowCardinality(String),
K8sCluster SimpleAggregateFunction(max, String),
K8sPodName SimpleAggregateFunction(max, String),
K8sDeploymentName SimpleAggregateFunction(max, String),
K8sStatefulSetName SimpleAggregateFunction(max, String),
K8sDaemonSetName SimpleAggregateFunction(max, String),
K8sNamespaceName SimpleAggregateFunction(max, String),
CloudPlatform SimpleAggregateFunction(max, String),
CloudProvider SimpleAggregateFunction(max, String),
FaasName SimpleAggregateFunction(max, String),
MapleSdkType SimpleAggregateFunction(max, String),
ProcessRuntimeName SimpleAggregateFunction(max, String),
SpanCount SimpleAggregateFunction(sum, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, ServiceName, DeploymentEnv)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS service_usage (
OrgId LowCardinality(String),
ServiceName LowCardinality(String),
Hour DateTime,
LogCount UInt64,
LogSizeBytes UInt64,
TraceCount UInt64,
TraceSizeBytes UInt64,
SumMetricCount UInt64,
SumMetricSizeBytes UInt64,
GaugeMetricCount UInt64,
GaugeMetricSizeBytes UInt64,
HistogramMetricCount UInt64,
HistogramMetricSizeBytes UInt64,
ExpHistogramMetricCount UInt64,
ExpHistogramMetricSizeBytes UInt64
)
ENGINE = SummingMergeTree
ORDER BY (OrgId, ServiceName, Hour)
TTL Hour + INTERVAL 365 DAY;
CREATE TABLE IF NOT EXISTS session_events (
OrgId LowCardinality(String),
SessionId String,
Timestamp DateTime64(9),
Seq UInt32 DEFAULT 0,
Type LowCardinality(String),
Url String DEFAULT '',
TraceId String DEFAULT '',
Level LowCardinality(String) DEFAULT '',
Message String DEFAULT '',
TargetSelector String DEFAULT '',
TargetText String DEFAULT '',
NetMethod LowCardinality(String) DEFAULT '',
NetUrl String DEFAULT '',
NetStatus UInt16 DEFAULT 0,
NetDurationMs UInt32 DEFAULT 0,
ErrorStack String DEFAULT '',
Attributes Map(String, String),
VisitorId String DEFAULT '',
UserId String DEFAULT '',
GroupId String DEFAULT '',
INDEX idx_type Type TYPE set(16) GRANULARITY 4
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, SessionId, Timestamp, Seq)
TTL toDate(Timestamp) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS session_replay_events (
OrgId LowCardinality(String),
SessionId String,
ChunkSeq UInt32,
Timestamp DateTime64(9),
DurationMs UInt32 DEFAULT 0,
EventCount UInt32 DEFAULT 0,
ByteSize UInt32 DEFAULT 0,
Events String,
IsCheckpoint UInt8 DEFAULT 0
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, SessionId, ChunkSeq)
TTL toDate(Timestamp) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS session_replays (
OrgId LowCardinality(String),
SessionId String,
StartTime DateTime64(9),
EndTime Nullable(DateTime64(9)),
DurationMs Nullable(UInt32),
Status LowCardinality(String),
UserId String,
UrlInitial String,
UserAgent String,
BrowserName LowCardinality(String),
OsName LowCardinality(String),
DeviceType LowCardinality(String),
Country LowCardinality(String) DEFAULT '',
ServiceName LowCardinality(String),
PageViews UInt32 DEFAULT 0,
ClickCount UInt32 DEFAULT 0,
ErrorCount UInt32 DEFAULT 0,
TraceIds Array(String) DEFAULT [],
ResourceAttributes Map(LowCardinality(String), String),
Version UInt32,
VisitorId String DEFAULT '',
VisitorIsNew UInt8 DEFAULT 0,
UserEmail String DEFAULT '',
UserName String DEFAULT '',
GroupId String DEFAULT '',
GroupName String DEFAULT '',
UserTraits Map(String, String) DEFAULT map(),
Referrer String DEFAULT '',
ReferrerHost LowCardinality(String) DEFAULT '',
UtmSource LowCardinality(String) DEFAULT '',
UtmMedium LowCardinality(String) DEFAULT '',
UtmCampaign LowCardinality(String) DEFAULT '',
UtmTerm String DEFAULT '',
UtmContent String DEFAULT '',
Host LowCardinality(String) DEFAULT '',
EntryPath String DEFAULT '',
ExitPath String DEFAULT '',
Language LowCardinality(String) DEFAULT '',
LastActivityAt Nullable(DateTime64(9))
)
ENGINE = ReplacingMergeTree
PARTITION BY toDate(StartTime)
ORDER BY (OrgId, SessionId)
TTL toDate(StartTime) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS span_metrics_calls_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
MetricName LowCardinality(String),
SpanKind LowCardinality(String),
AttrFingerprint UInt64,
ResourceFingerprint UInt64,
StartTimeUnix DateTime64(9),
LastValue AggregateFunction(argMax, Float64, DateTime64(9))
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, ServiceName, MetricName, SpanKind, AttrFingerprint, ResourceFingerprint, StartTimeUnix)
TTL toDate(Hour) + INTERVAL 90 DAY;
CREATE TABLE IF NOT EXISTS trace_detail_spans (
OrgId LowCardinality(String),
Timestamp DateTime64(9),
TraceId String,
SpanId String,
ParentSpanId String,
SpanName LowCardinality(String),
SpanKind LowCardinality(String),
ServiceName LowCardinality(String),
Duration UInt64 DEFAULT 0,
StatusCode LowCardinality(String),
StatusMessage String,
SpanAttributes Map(LowCardinality(String), String),
ResourceAttributes Map(LowCardinality(String), String)
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, TraceId, SpanId)
TTL toDate(Timestamp) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS trace_facets_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
SpanName String,
HttpMethod LowCardinality(String),
HttpStatusCode LowCardinality(String),
DeploymentEnv LowCardinality(String),
ServiceNamespace LowCardinality(String),
HasError UInt8,
TraceCount SimpleAggregateFunction(sum, UInt64),
DurationMin SimpleAggregateFunction(min, UInt64),
DurationMax SimpleAggregateFunction(max, UInt64),
DurationQuantiles AggregateFunction(quantilesTDigest(0.5, 0.95), UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError)
TTL Hour + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS trace_list_mv (
OrgId LowCardinality(String),
TraceId String,
Timestamp DateTime,
ServiceName LowCardinality(String),
SpanName String,
SpanKind LowCardinality(String),
Duration UInt64,
StatusCode LowCardinality(String),
HttpMethod LowCardinality(String),
HttpRoute String,
HttpStatusCode LowCardinality(String),
DeploymentEnv LowCardinality(String),
HasError UInt8,
TraceState String,
ServiceNamespace LowCardinality(String),
INDEX idx_service_namespace ServiceNamespace TYPE set(1000) GRANULARITY 4
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, Timestamp, TraceId)
TTL Timestamp + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS traces (
OrgId LowCardinality(String),
Timestamp DateTime64(9),
TraceId String,
SpanId String,
ParentSpanId String,
TraceState String,
SpanName LowCardinality(String),
SpanKind LowCardinality(String),
ServiceName LowCardinality(String),
ResourceSchemaUrl String,
ResourceAttributes Map(LowCardinality(String), String),
ScopeSchemaUrl String,
ScopeName String,
ScopeVersion String,
ScopeAttributes Map(LowCardinality(String), String),
Duration UInt64 DEFAULT 0,
StatusCode LowCardinality(String),
StatusMessage String,
SpanAttributes Map(LowCardinality(String), String),
EventsTimestamp Array(DateTime64(9)),
EventsName Array(LowCardinality(String)),
EventsAttributes Array(Map(LowCardinality(String), String)),
LinksTraceId Array(String),
LinksSpanId Array(String),
LinksTraceState Array(String),
LinksAttributes Array(Map(LowCardinality(String), String)),
SampleRate Float64 DEFAULT multiIf(SpanAttributes['SampleRate'] != '' AND toFloat64OrZero(SpanAttributes['SampleRate']) >= 1.0, toFloat64OrZero(SpanAttributes['SampleRate']), match(TraceState, 'th:[0-9a-f]+'), 1.0 / greatest(1.0 - reinterpretAsUInt64(reverse(unhex(rightPad(extract(TraceState, 'th:([0-9a-f]+)'), 16, '0')))) / pow(2.0, 64), 0.0001), 1.0),
IsEntryPoint UInt8 DEFAULT if(SpanKind IN ('Server', 'Consumer') OR ParentSpanId = '', 1, 0),
ResourceAttributeItems Array(String) DEFAULT arrayMap((k, v) -> concat(k, char(31), v), mapKeys(ResourceAttributes), mapValues(ResourceAttributes)),
ScopeAttributeItems Array(String) DEFAULT arrayMap((k, v) -> concat(k, char(31), v), mapKeys(ScopeAttributes), mapValues(ScopeAttributes)),
SpanAttributeItems Array(String) DEFAULT arrayMap((k, v) -> concat(k, char(31), v), mapKeys(SpanAttributes), mapValues(SpanAttributes)),
INDEX idx_trace_id TraceId TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_span_attr_keys mapKeys(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_span_attr_vals mapValues(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_attr_keys mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_attr_vals mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_scope_attr_keys mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_scope_attr_vals mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (OrgId, ServiceName, SpanName, toDateTime(Timestamp))
TTL toDate(Timestamp) + INTERVAL 30 DAY;
CREATE TABLE IF NOT EXISTS traces_aggregates_hourly (
OrgId LowCardinality(String),
Hour DateTime,
ServiceName LowCardinality(String),
SpanName LowCardinality(String),
SpanKind LowCardinality(String),
StatusCode LowCardinality(String),
IsEntryPoint UInt8,
DeploymentEnv LowCardinality(String),
WeightedCount SimpleAggregateFunction(sum, Float64),
WeightedDurationSum SimpleAggregateFunction(sum, Float64),
WeightedErrorCount SimpleAggregateFunction(sum, Float64),
DurationQuantiles AggregateFunction(quantilesTDigestWeighted(0.5, 0.95, 0.99), UInt64, UInt32),
DurationMin SimpleAggregateFunction(min, UInt64),
DurationMax SimpleAggregateFunction(max, UInt64)
)
ENGINE = AggregatingMergeTree
PARTITION BY toDate(Hour)
ORDER BY (OrgId, Hour, ServiceName, SpanName, SpanKind, StatusCode, IsEntryPoint, DeploymentEnv)
TTL toDate(Hour) + INTERVAL 365 DAY;
CREATE MATERIALIZED VIEW IF NOT EXISTS ai_crawler_requests_mv TO ai_crawler_requests AS
SELECT
OrgId,
Timestamp,
TraceId,
ServiceName,
arrayElement(['GPTBot', 'OAI-SearchBot', 'ChatGPT-User', 'ClaudeBot', 'anthropic-ai', 'Claude-SearchBot', 'Claude-User', 'PerplexityBot', 'Perplexity-User', 'Meta-ExternalAgent', 'Meta-WebIndexer', 'Meta-ExternalFetcher', 'Bytespider', 'MistralAI-User', 'CCBot', 'Amazonbot', 'DuckAssistBot', 'cohere-training-data-crawler', 'cohere-ai'], multiSearchFirstIndexCaseInsensitive(coalesce(nullIf(SpanAttributes['user_agent.original'], ''), nullIf(SpanAttributes['http.user_agent'], ''), ''), ['GPTBot', 'OAI-SearchBot', 'ChatGPT-User', 'ClaudeBot', 'anthropic-ai', 'Claude-SearchBot', 'Claude-User', 'PerplexityBot', 'Perplexity-User', 'meta-externalagent', 'meta-webindexer', 'meta-externalfetcher', 'Bytespider', 'MistralAI-User', 'CCBot', 'Amazonbot', 'DuckAssistBot', 'cohere-training-data-crawler', 'cohere-ai'])) AS Crawler,
lower(replaceRegexpOne(coalesce(nullIf(SpanAttributes['server.address'], ''), nullIf(SpanAttributes['http.host'], ''), nullIf(SpanAttributes['net.host.name'], ''), nullIf(domain(SpanAttributes['url.full']), ''), nullIf(domain(SpanAttributes['http.url']), ''), ''), ':[0-9]+$', '')) AS Host,
leftUTF8(coalesce(nullIf(SpanAttributes['url.path'], ''), nullIf(replaceRegexpOne(SpanAttributes['http.target'], '[?#].*$', ''), ''), nullIf(path(SpanAttributes['url.full']), ''), nullIf(path(SpanAttributes['http.url']), ''), ''), 512) AS Path,
toUInt16OrZero(coalesce(nullIf(SpanAttributes['http.response.status_code'], ''), nullIf(SpanAttributes['http.status_code'], ''), '')) AS HttpStatus
FROM traces
WHERE SpanKind = 'Server'
AND multiSearchFirstIndexCaseInsensitive(coalesce(nullIf(SpanAttributes['user_agent.original'], ''), nullIf(SpanAttributes['http.user_agent'], ''), ''), ['GPTBot', 'OAI-SearchBot', 'ChatGPT-User', 'ClaudeBot', 'anthropic-ai', 'Claude-SearchBot', 'Claude-User', 'PerplexityBot', 'Perplexity-User', 'meta-externalagent', 'meta-webindexer', 'meta-externalfetcher', 'Bytespider', 'MistralAI-User', 'CCBot', 'Amazonbot', 'DuckAssistBot', 'cohere-training-data-crawler', 'cohere-ai']) > 0
AND leftUTF8(coalesce(nullIf(SpanAttributes['url.path'], ''), nullIf(replaceRegexpOne(SpanAttributes['http.target'], '[?#].*$', ''), ''), nullIf(path(SpanAttributes['url.full']), ''), nullIf(path(SpanAttributes['http.url']), ''), ''), 512) != '';
CREATE MATERIALIZED VIEW IF NOT EXISTS ai_trace_index_mv TO ai_trace_index AS
SELECT
OrgId,
Timestamp,
TraceId,
SpanAttributes['maple_ai.session.id'] AS SessionId,
SpanAttributes['maple_ai.vendor.id'] AS VendorId,
ServiceName,
coalesce(nullIf(ResourceAttributes['deployment.environment.name'], ''), ResourceAttributes['deployment.environment']) AS DeploymentEnv,
SpanAttributes['maple_ai.model'] AS Model,
SpanAttributes['maple_ai.agent.name'] AS AgentName,
SpanAttributes['maple_ai.tool.name'] AS ToolName,
SpanId,