1_traces.sql 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. drop table if exists otel.traces_local on cluster default sync;
  2. CREATE TABLE if not exists otel.traces_local on cluster default
  3. (
  4. `Timestamp` DateTime64(9) CODEC (Delta(8), ZSTD(1)),
  5. `TraceId` String CODEC (ZSTD(1)),
  6. `SpanId` String CODEC (ZSTD(1)),
  7. `ParentSpanId` String CODEC (ZSTD(1)),
  8. `TraceState` String CODEC (ZSTD(1)),
  9. `SpanName` LowCardinality(String) CODEC (ZSTD(1)),
  10. `SpanKind` Int8 CODEC (ZSTD(1)),
  11. `ServiceName` LowCardinality(String) CODEC (ZSTD(1)),
  12. `ResourceAttributes` Map(LowCardinality(String), String) CODEC (ZSTD(2)),
  13. `ScopeName` String CODEC (ZSTD(10)),
  14. `ScopeVersion` String CODEC (ZSTD(3)),
  15. `SpanAttributes` Map(LowCardinality(String), String) CODEC (ZSTD(1)),
  16. `Duration` Int64 CODEC (ZSTD(1)),
  17. `StatusCode` Int32 CODEC (ZSTD(1)),
  18. `StatusMessage` String CODEC (ZSTD(1)),
  19. `Events.Timestamp` Array(DateTime65(9)) CODEC (ZSTD(1)),
  20. `Events.Name` Array(LowCardinality(String)) CODEC (ZSTD(1)),
  21. `Events.Attributes` Array(Map(LowCardinality(String), String)) CODEC (ZSTD(1)),
  22. `Links.TraceId` Array(String) CODEC (ZSTD(1)),
  23. `Links.SpanId` Array(String) CODEC (ZSTD(1)),
  24. `Links.TraceState` Array(String) CODEC (ZSTD(1)),
  25. `Links.Attributes` Array(Map(LowCardinality(String), String)) CODEC (ZSTD(1)),
  26. `HttpCode` Int32,
  27. `HttpMethod` String CODEC (ZSTD(1)),
  28. `HttpURL` String CODEC (ZSTD(1)),
  29. `ContainerId` String CODEC (ZSTD(1)),
  30. `srcIP` String CODEC (ZSTD(1)),
  31. `srcPort` Int32 CODEC (ZSTD(1)),
  32. `targetIP` String CODEC (ZSTD(1)),
  33. `targetPort` Int32 CODEC (ZSTD(1)),
  34. `RPCType` String,
  35. `RPCName` String,
  36. `RPCRequest` Map(LowCardinality(String), String),
  37. `RPCResult` Int8,
  38. `FuncNameSpace` String,
  39. `FuncName` String,
  40. `FuncLineNO` Int32,
  41. `FuncResult` Int32,
  42. `dbStatement` String CODEC (ZSTD(1)),
  43. `dbConnectionString` String CODEC (ZSTD(1)),
  44. `Exceptions.type` Array(String),
  45. `Exceptions.message` Array(String),
  46. `Exceptions.stacktrace` Array(String),
  47. `AppAlias` String,
  48. INDEX idx_trace_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1,
  49. INDEX idx_duration Duration TYPE minmax GRANULARITY 1
  50. )
  51. ENGINE = ReplicatedMergeTree('/clickhouse/otel/tables/{shard}/raw_traces_local', '{replica}')
  52. PARTITION BY toDate(Timestamp)
  53. PRIMARY KEY (Timestamp, ServiceName, TraceId)
  54. ORDER BY (Timestamp, ServiceName, TraceId)
  55. TTL toDateTime(Timestamp) + toIntervalDay(10)
  56. SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
  57. drop table if exists otel.traces on cluster default sync;
  58. CREATE TABLE if not exists otel.traces on cluster default as otel.traces_local
  59. ENGINE = Distributed('default', 'otel', 'traces_local', rand());