1pub mod attributes;
16pub mod span;
17pub mod v0;
18pub mod v1;
19
20use api::v1::RowInsertRequests;
21pub use common_catalog::consts::{
22 PARENT_SPAN_ID_COLUMN, SPAN_ID_COLUMN, SPAN_NAME_COLUMN, TRACE_ID_COLUMN,
23};
24use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
25use pipeline::{GreptimePipelineParams, PipelineWay};
26use session::context::QueryContextRef;
27
28use crate::error::{NotSupportedSnafu, Result};
29use crate::query_handler::PipelineHandlerRef;
30
31pub const SERVICE_NAME_COLUMN: &str = "service_name";
33pub const TIMESTAMP_COLUMN: &str = "timestamp";
34pub const DURATION_NANO_COLUMN: &str = "duration_nano";
35pub const SPAN_KIND_COLUMN: &str = "span_kind";
36pub const SPAN_STATUS_CODE: &str = "span_status_code";
37pub const SPAN_STATUS_MESSAGE_COLUMN: &str = "span_status_message";
38pub const SPAN_ATTRIBUTES_COLUMN: &str = "span_attributes";
39pub const SPAN_EVENTS_COLUMN: &str = "span_events";
40pub const SCOPE_NAME_COLUMN: &str = "scope_name";
41pub const SCOPE_VERSION_COLUMN: &str = "scope_version";
42pub const RESOURCE_ATTRIBUTES_COLUMN: &str = "resource_attributes";
43pub const TRACE_STATE_COLUMN: &str = "trace_state";
44
45pub const KEY_SERVICE_NAME: &str = "service.name";
47pub const KEY_SERVICE_INSTANCE_ID: &str = "service.instance.id";
48pub const KEY_SPAN_KIND: &str = "span.kind";
49
50pub const KEY_OTEL_SCOPE_NAME: &str = "otel.scope.name";
52pub const KEY_OTEL_SCOPE_VERSION: &str = "otel.scope.version";
53pub const KEY_OTEL_STATUS_CODE: &str = "otel.status_code";
54pub const KEY_OTEL_STATUS_MESSAGE: &str = "otel.status_description";
55pub const KEY_OTEL_STATUS_ERROR_KEY: &str = "error";
56pub const KEY_OTEL_TRACE_STATE: &str = "w3c.tracestate";
57
58pub const SPAN_KIND_PREFIX: &str = "SPAN_KIND_";
61
62pub const SPAN_STATUS_PREFIX: &str = "STATUS_CODE_";
64pub const SPAN_STATUS_UNSET: &str = "STATUS_CODE_UNSET";
65pub const SPAN_STATUS_ERROR: &str = "STATUS_CODE_ERROR";
66
67pub fn to_grpc_insert_requests(
70 request: ExportTraceServiceRequest,
71 pipeline: PipelineWay,
72 pipeline_params: GreptimePipelineParams,
73 table_name: String,
74 query_ctx: &QueryContextRef,
75 pipeline_handler: PipelineHandlerRef,
76) -> Result<(RowInsertRequests, usize)> {
77 match pipeline {
78 PipelineWay::OtlpTraceDirectV0 => v0::v0_to_grpc_insert_requests(
79 request,
80 pipeline,
81 pipeline_params,
82 table_name,
83 query_ctx,
84 pipeline_handler,
85 ),
86 PipelineWay::OtlpTraceDirectV1 => v1::v1_to_grpc_insert_requests(
87 request,
88 pipeline,
89 pipeline_params,
90 table_name,
91 query_ctx,
92 pipeline_handler,
93 ),
94 _ => NotSupportedSnafu {
95 feat: "Unsupported pipeline for trace",
96 }
97 .fail(),
98 }
99}