Module: OpenTelemetry::Helpers::SqlProcessor::SqlCommenter::SqlQueryPropagator

Extended by:
SqlQueryPropagator
Included in:
SqlQueryPropagator
Defined in:
lib/opentelemetry/helpers/sql_processor/commenter.rb

Overview

SqlQueryPropagator propagates trace context using SQL comments according to the SQL Commenter specification.

This propagator implements the same interface as the Vitess propagator and can be used as a drop-in replacement.

Examples:

propagator = OpenTelemetry::Helpers::SqlProcessor::SqlCommenter.sql_query_propagator
sql = "SELECT * FROM users"
propagator.inject(sql, context: current_context)
# => "SELECT * FROM users /*traceparent='00-...',tracestate='...'*/"

Instance Method Summary collapse

Instance Method Details

#inject(carrier, context: OpenTelemetry::Context.current, setter: SqlQuerySetter) ⇒ nil

Injects trace context into a SQL query as a comment



72
73
74
75
76
77
78
79
80
# File 'lib/opentelemetry/helpers/sql_processor/commenter.rb', line 72

def inject(carrier, context: OpenTelemetry::Context.current, setter: SqlQuerySetter)
  # Use the global propagator to extract headers into a hash
  headers = {}
  OpenTelemetry.propagation.inject(headers, context: context)

  # Pass the headers to our SQL comment setter
  setter.set(carrier, headers)
  nil
end