Open florianmutter opened 5 months ago
As I can see, ddtrace can be integrated this way (from the doc)
import os
# Must be set before ddtrace is imported!
os.environ["DD_TRACE_OTEL_ENABLED"] = "true"
from opentelemetry.trace import set_tracer_provider
from ddtrace.opentelemetry import TracerProvider
set_tracer_provider(TracerProvider())
You can adopt this example to FastStream the following way
import os
# Must be set before ddtrace is imported!
os.environ["DD_TRACE_OTEL_ENABLED"] = "true"
from opentelemetry import trace
from ddtrace.opentelemetry import TracerProvider
tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
from faststream import FastStream
from faststream.nats import NatsBroker
from faststream.nats.opentelemetry import NatsTelemetryMiddleware
broker = NatsBroker(
middlewares=(
NatsTelemetryMiddleware(tracer_provider=tracer_provider),
)
)
app = FastStream(broker)
I am not experted enough to tell that is the thing you want, but all look fine for me
@draincoder what do you think?
It's a good idea, I'll look at which other libraries have an opentelemetry-api
implementation and analyze this proposal.
To make it easier to switch the opentelemetry implementation it should be up to the user to install an implementation. The documentation can suggest
opentelemetry-sdk
but it should not be installed by default. This would allow a user to replaceopentelemetry-sdk
with a different implementation (e.g. Datadogs ddtrace that also implements the opentelemetry-api: https://ddtrace.readthedocs.io/en/stable/api.html#opentelemetry-api)This is also recommended by OpenTelemetry here: https://opentelemetry.io/docs/concepts/instrumentation/libraries/#opentelemetry-api