open-telemetry / opentelemetry-cpp

The OpenTelemetry C++ Client
https://opentelemetry.io/
Apache License 2.0
849 stars 403 forks source link

[Exporter] Prevent infinite recursion with grpc #3039

Open marcalff opened 1 month ago

marcalff commented 1 month ago

The grpc C++ library is instrumented using opentelemetry-cpp:

The opentelemetry-cpp OTLP GRPC exporter uses grpc

In the OTLP GRPC exporter implementation, opentelemetry-cpp needs to:

so avoid infinite recursion.

This is blocking:

This is blocked by the spec:

lalitb commented 1 month ago

Thanks for raising the issue. Just to add the approach used by otel-python - https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-python%20_SUPPRESS_INSTRUMENTATION_KEY%20&type=code

However, this approach has some constraint. Any instrumentation that needs to be suppressed in the libraries used by the OTLP exporter should be invoked from the exporter thread since the active context is thread-local in otel-cpp.

Similar approach used in otel-dotnet - https://github.com/open-telemetry/opentelemetry-dotnet/blob/1a836432840d657926923ccce4d09c4a4e08728c/src/OpenTelemetry/SuppressInstrumentationScope.cs#L12

punya commented 6 days ago

Here is a similar issue with a fix (OTel-C++ but a different gRPC-based exporter): https://github.com/googleapis/google-cloud-cpp/issues/14611