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 SDK dependency from auto-instrumentation #1420

Merged
merged 16 commits into from
Dec 14, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

from pkg_resources import iter_entry_points

from opentelemetry.instrumentation.auto_instrumentation.components import (
initialize_components,
)

logger = getLogger(__file__)

Expand All @@ -35,6 +32,15 @@ def auto_instrument():
raise exc


def initialize_components():
for entry_point in iter_entry_points("opentelemetry_configure"):
try:
entry_point.load()().configure() # type: ignore
except Exception as exc: # pylint: disable=broad-except
logger.exception("Configuration of %s failed", entry_point.name)
raise exc


def initialize():
try:
initialize_components()
Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-sdk/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ opentelemetry_tracer_provider =
sdk_tracer_provider = opentelemetry.sdk.trace:TracerProvider
opentelemetry_propagator =
b3 = opentelemetry.sdk.trace.propagation.b3_format:B3Format
opentelemetry_exporter =
console_span = opentelemetry.sdk.trace.export:ConsoleSpanExporter
console_metric = opentelemetry.sdk.metrics.export:ConsoleSpanExporter
opentelemetry_configure =
sdk_configurator = opentelemetry.sdk.configuration:Configurator

[options.extras_require]
test =
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ def initialize_components():
# some boilerplate in order to make sure current implementation does not
# lock us out of supporting metrics later without major surgery.
init_metrics(metric_exporters)


class Configurator:
def configure(self):
initialize_components()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be just a function as well right?

Suggested change
class Configurator:
def configure(self):
initialize_components()
def configure():
initialize_components()

and then in sitecustomize.py it would just be entry_point.load()()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmno, the load method will yield the object that is pointed by the entry point value, in this case opentelemetry.sdk.configuration:Configurator which is a class. An entry point can point to a method, or some other object, but what this approach that we have been using is to declare an ABC in the API that mandates that certain method is implemented in order for the entry pointed classes to have it and run it when sitecustomize is invoked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, having the ABC would be helpful. Where would that definition go though? In opentelemetry-instrumentation or opentelemetry-sdk?

Does that mean that the other package would have to take the package that includes the ABC as a dependency?

(The opentelemtery-sdk to have its Configurator up to requirements and the opentelmetry-instrumentation to be able to validate classes it finds through the entry points)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ABC will be in the API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, wait, that ABC should be in opentelemetry-instrumentation. Sorry 😅