Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove implicit dependency on TracerProvider from Tracer #1181

Closed
owais opened this issue Sep 30, 2020 · 7 comments
Closed

Remove implicit dependency on TracerProvider from Tracer #1181

owais opened this issue Sep 30, 2020 · 7 comments
Assignees
Labels
good first issue Good first issue help wanted release:required-for-ga To be resolved before GA release

Comments

@owais
Copy link
Contributor

owais commented Sep 30, 2020

Today, the main tracer implementation accept a source argument during initialization which refers to the tracer provider instance. The tracer then stores a reference to the source (tracer provider) and uses it to access a number of different things such as sampler, resource, span processor and soon ID generator. This implicitly couples SDK tracer and tracer provider implementations. Anyone implementing a custom tracer provider must satisfy such undocumented tracer provider interface/behavior.

I propose we make all tracer dependencies explicitly to the tracer during initialization. Each dependency can be it's own argument to Tracer.__init__ or we can bundle up all such dependencies into a single object and pass that in. This will de-couple tracer and tracer provider and allow users to implement one or the other without any surprises.

discussion: #1153 (comment)

@lzchen lzchen added good first issue Good first issue help wanted release:required-for-ga To be resolved before GA release labels Sep 30, 2020
@codeboten codeboten changed the title Remove implicit dependency on TraceProvider from Tracer Remove implicit dependency on TracerProvider from Tracer Oct 8, 2020
@robwknox
Copy link
Contributor

@codeboten submitted PR #1295

@codeboten
Copy link
Contributor

@codeboten submitted PR #1295

thanks!

@NathanielRN
Copy link
Contributor

@robwknox Just wondering if in addition to @owais 's suggestion, you considered adding to the TracerProvider API.

So in opentelemetry-api/src/opentelemetry/trace/__init__.py instead of just

class TracerProvider(abc.ABC):
    @abc.abstractmethod
    def get_tracer(
        self,
        instrumenting_module_name: str,
        instrumenting_library_version: str = "",
    ) -> "Tracer":

we would have

class TracerProvider(abc.ABC):
    sampler: Sampler
    resource: Resource
    span_processor: SpanProcessor
    ids_generator: IdsGenerator

    @abc.abstractmethod
    def get_tracer(
        self,
        instrumenting_module_name: str,
        instrumenting_library_version: str = "",
    ) -> "Tracer":

I know the specifications on TracerProvider does not include these fields. However, this solution would require Custom Implementations of TracerProvider to provide these fields, which would make them compatible with the Tracer class, but which may be too restrictive to people wanting to do their own thing.

@robwknox
Copy link
Contributor

@NathanielRN I like the suggestion (and it would mimic go's impl) but the snag I see is that Sampler, Resource, and SpanProcessor are only defined in the SDK so we would have to add those into the API as part of this. Is that appropriate / worthwhile?

srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this issue Nov 1, 2020
@lzchen
Copy link
Contributor

lzchen commented Nov 2, 2020

@robwknox
Sampler and SpanProcessor are purely SDK concepts so we probably don't want them in the API.

so we would have to add those into the API as part of this

How come this is the case? We already pass in these variables as part of TracerProvider without them being part of the API.

@robwknox
Copy link
Contributor

robwknox commented Nov 2, 2020

@lzchen

How come this is the case? We already pass in these variables as part of TracerProvider without them being part of the API.

In order to accomplish the type hinting of the new fields @NathanielRN is suggesting for the TracerProvider API definition.

@lzchen
Copy link
Contributor

lzchen commented Nov 9, 2020

@robwknox
We can't.

Sampler and SpanProcessor are purely SDK concepts so we probably don't want them in the API.

@lzchen lzchen closed this as completed Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good first issue help wanted release:required-for-ga To be resolved before GA release
Projects
None yet
Development

No branches or pull requests

5 participants