Skip to content

Commit

Permalink
auto instrumentation parameter proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Apr 18, 2024
1 parent 47d5ad7 commit 2b46bf2
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,37 +345,54 @@ def _import_id_generator(id_generator_name: str) -> IdGenerator:
raise RuntimeError(f"{id_generator_name} is not an IdGenerator")


def _initialize_components(auto_instrumentation_version):
trace_exporters, metric_exporters, log_exporters = _import_exporters(
_get_exporter_names("traces"),
_get_exporter_names("metrics"),
_get_exporter_names("logs"),
def _initialize_components(**kwargs):
auto_instrumentation_version = kwargs.get("auto_instrumentation_version")
# Could be trace_exporters or span_exporters
span_exporter_names = kwargs.get("span_exporter_names")
metric_exporter_names = kwargs.get("metric_exporter_names")
log_exporter_names = kwargs.get("log_exporter_names")
sampler_name = kwargs.get("sampler_name")
# Could be attribute dict or Resource object
resource_attributes = kwargs.get("resource_attributes")
logging_enabled = kwargs.get("logging_enabled")
# Could come before or after
span_exporters, metric_exporters, log_exporters = _import_exporters(
span_exporter_names + _get_exporter_names("traces"),
metric_exporter_names + _get_exporter_names("metrics"),
log_exporter_names + _get_exporter_names("logs"),
)
sampler_name = _get_sampler()
if sampler_name is None:
sampler_name = _get_sampler()
sampler = _import_sampler(sampler_name)
id_generator_name = _get_id_generator()
if id_generator_name is None:
id_generator_name = _get_id_generator()
id_generator = _import_id_generator(id_generator_name)
# if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name
# from the env variable else defaults to "unknown_service"
auto_resource = {}
auto_resource_attributes = {}
if resource_attributes is not None:
auto_resource_attributes = resource_attributes
# populate version if using auto-instrumentation
if auto_instrumentation_version:
auto_resource[
auto_resource_attributes[
ResourceAttributes.TELEMETRY_AUTO_VERSION
] = auto_instrumentation_version
resource = Resource.create(auto_resource)
resource = Resource.create(auto_resource_attributes)

_init_tracing(
exporters=trace_exporters,
exporters=span_exporters,
id_generator=id_generator,
sampler=sampler,
resource=resource,
)
_init_metrics(metric_exporters, resource)
logging_enabled = os.getenv(
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "false"
)
if logging_enabled.strip().lower() == "true":
# This could also be paramaterized
if logging_enabled is None:
logging_enabled = os.getenv(
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "false"
).strip().lower() == "true"
# Could be string or bool
if logging_enabled:
_init_logging(log_exporters, resource)


Expand Down Expand Up @@ -419,4 +436,5 @@ class _OTelSDKConfigurator(_BaseConfigurator):
"""

def _configure(self, **kwargs):
_initialize_components(kwargs.get("auto_instrumentation_version"))
# _initialize_components(kwargs.get("auto_instrumentation_version"))
_initialize_components(**kwargs)

0 comments on commit 2b46bf2

Please sign in to comment.