Open kashifkhan opened 8 months ago
Facing the same issue. Although I'm using mypy 1.0.0.
Did you find any resolution yet @kashifkhan ?
Does something like this work for you?
diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py
index 9f9abe0f..e9ee0cae 100644
--- a/opentelemetry-api/src/opentelemetry/trace/__init__.py
+++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py
@@ -527,7 +527,10 @@ def set_tracer_provider(tracer_provider: TracerProvider) -> None:
_set_tracer_provider(tracer_provider, log=True)
-def get_tracer_provider() -> TracerProvider:
+_TracerProviderType = typing.TypeVar("_TracerProviderType", bound=TracerProvider)
+
+
+def get_tracer_provider() -> _TracerProviderType:
"""Gets the current global :class:`~.TracerProvider` object."""
if _TRACER_PROVIDER is None:
# if a global tracer provider has not been set either via code or env
I had the same issue. I made a "fix" like this.
tracerProvider = TracerProvider()
tracerProvider.add_span_processor(BatchSpanProcessor(AzureMonitorTraceExporter()))
trace.set_tracer_provider(tracerProvider)
Yeah, there are several examples that use this pattern where the example script creates a TracerProvider
, hands it to the API, then immediately asks for it from the API but with the type of the abstract base class, from which it calls a method that doesn't exist on that type.
Does anyone know why? I thought maybe the intent was to demonstrate how to get the tracer provider via the API, but if that's true I don't think this is the best way.
When running mypy 1.8 on some of our samples, an error is generated saying that
"TracerProvider" has no attribute "add_span_processor"
From the looks of it, seems like get_tracer_provider is returning the opentelemetry.trace.TracerProvider ABC, however opentelemetry.sdk.trace.TracerProvider has more methods defined than the ABC
Repro:
pip list
The code snippet above is from our samples, but it looks similar to the one in the cookbook.