open-telemetry / opentelemetry-php

The OpenTelemetry PHP Library
https://opentelemetry.io/docs/instrumentation/php/
Apache License 2.0
751 stars 186 forks source link

TracerProvider IdGenerator parameter is not used for trace id/span id generation #281

Closed hrodic closed 3 years ago

hrodic commented 3 years ago

Describe your environment

PHP 7.3 Commit of dev-main version: https://github.com/open-telemetry/opentelemetry-php/commit/bb0bbafec1d48509171aa12be68182075ef8e459

Steps to reproduce Construct TracerProvider with custom generator

$tracer = (new TracerProvider(null, null, new TracingIdGenerator())) ->addSpanProcessor(new BatchSpanProcessor($exporter, Clock::get())) ->getTracer('io.opentelemetry.contrib.php', 'dev-main');

What is the expected behavior? I would expect the traceId of a new span to use the generator specified. If the new generator uses 8 bytes hex instead of 16 i would like to see it (per example to make it W3C compatible with tracing formats of trace and span ids). $clientSpan->getContext()->getTraceId();

What is the actual behavior? 16 byte hex ids returned

Additional context I was investigating on how to make context propagation using TraceContext class of the same project after using the w3c trace format.

$parentContext = TraceContext::extract($carrier, new PropagationMap());

Fatal error: Uncaught InvalidArgumentException: SpanID must be exactly 8 bytes (16 chars) and at least one non-zero byte, got 0c365901539b66fcb52c24a5329de59f

bobstrecansky commented 3 years ago

@Fahmy-Mohammed is working on finishing up w3c format issues, maybe he can shed some light on this issue.

deki commented 3 years ago

Just hit the same issue. I think the problem is that startActiveSpan always calls SpanContext::generate(true) and this uses randomHex instead of the IdGenerator.