clickhouse-connect icon indicating copy to clipboard operation
clickhouse-connect copied to clipboard

Enable passing OTEL trace context to client's query methods

Open martijnthe opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

As per the ClickHouse docs:

ClickHouse accepts trace context HTTP headers, as described by the W3C recommendation.

At the moment, there is no clean way to pass Open Telemetry trace context when calling a client's query methods. I realize the feature is "experimental", but the format of the header and OTEL itself can be deemed as stable. Therefore it's unlikely to change at the client layer and probably fine to already implement (but of course up to the maintainers to decide).

Describe the solution you'd like

I'd like to be able to pass a trace_context: TraceContext query arg to each of the query methods, which would set the trace context headers/metadata when making the request to the server.

The TraceContext object would contain a subset of the fields from OTEL's SpanContext -- only the fields that need to be included in the header.

Describe alternatives you've considered

One can implement this functionality by subclassing the client class of course, but it would be nice if it's built-in.

Additional context

  • ClickHouse OTEL documentation: https://clickhouse.com/docs/en/operations/opentelemetry
  • W3C trace context spec: https://www.w3.org/TR/trace-context/
  • OTEL python library SpanContext: https://opentelemetry-python.readthedocs.io/en/latest/api/trace.span.html?highlight=SpanContext#opentelemetry.trace.span.SpanContext

martijnthe avatar Feb 17 '24 11:02 martijnthe