wyhaines / opentelemetry-api.cr

The core of open telemetry instrumentation is the OpenTelemetry API/SDK. The initial aim of this shard is to implement the OpenTelemetry specification for metrics, traces, and logs.
Apache License 2.0
12 stars 1 forks source link

Propagator trace context extract to update trace_id from headers #22

Closed miry closed 2 years ago

miry commented 2 years ago

It is not clear how to use Context after propagation, as it does not have trace_id information and could not create spancontext after.

here is an example how i could use:

def call(context) : Nil
  request = context.request
  tracer = OpenTelemetry.trace
  span_context = OpenTelemetry::Propagation::TraceContext.new.extract(request.headers)
  if span_context
    tracer.trace_id = span_context.trace_id
    tracer.span_context = span_context
  end

  tracer.in_span()....

The ideal would be

def call(context) : Nil
  request = context.request
  ot_context = OpenTelemetry::Propagation::TraceContext.new.extract(request.headers, context: OpenTelemetry::Context.current)
  OpenTelemetry::Context.with(context: ot_context) do
    OpenTelemetry.trace.in_span()....
  end

I have a little knowledge OpenTelemetry::Context.with and would like to have a help.

wyhaines commented 2 years ago

I am closing this PR because I am not sure that it does quite what I think that it should, and all of the code that it applies to has been moved to the SDK repo. The issue has been recreated there, though: https://github.com/wyhaines/opentelemetry-sdk.cr/issues/1