Skip to content

Commit

Permalink
Auto instrumentation paramaters proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Apr 18, 2024
1 parent 7656bdb commit 552332a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 14 additions & 0 deletions opentelemetry-distro/src/opentelemetry/distro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ def _configure(self, **kwargs):
os.environ.setdefault(OTEL_TRACES_EXPORTER, "otlp")
os.environ.setdefault(OTEL_METRICS_EXPORTER, "otlp")
os.environ.setdefault(OTEL_EXPORTER_OTLP_PROTOCOL, "grpc")
# Since the distro sets these env vars, these params are not necesary.
# However they could replace these env var defaults.
# Otherwise, they just serve as an example.
configuration_kwargs = {
# Could be trace_exporters or span_exporters
"span_exporter_names": ("otlp"),
"metric_exporter_names": ("otlp"),
"log_exporter_names": ("otlp"),
"sampler_name": None,
# Could be attribute dict or Resource object
"resource_attributes": {},
# Could be string or bool
"logging_enabled": False,
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def _load_instrumentors(distro):
entry_point.load()()


def _load_configurators():
def _load_configurators(**configuration_kwargs):
configuration_kwargs["auto_instrumentation_version"] =__version__
configurator_name = environ.get(OTEL_PYTHON_CONFIGURATOR, None)
configured = None
for entry_point in iter_entry_points("opentelemetry_configurator"):
Expand All @@ -110,7 +111,7 @@ def _load_configurators():
configurator_name is None
or configurator_name == entry_point.name
):
entry_point.load()().configure(auto_instrumentation_version=__version__) # type: ignore
entry_point.load()().configure(**configuration_kwargs) # type: ignore
configured = entry_point.name
else:
_logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def initialize():

try:
distro = _load_distro()
distro.configure()
_load_configurators()
configuration_kwargs = distro.configure()
_load_configurators(**configuration_kwargs)
_load_instrumentors(distro)
except Exception: # pylint: disable=broad-except
logger.exception("Failed to auto initialize opentelemetry")
Expand Down

0 comments on commit 552332a

Please sign in to comment.