Skip to content

Commit 2b46bf2

Browse files
committed
auto instrumentation parameter proposal
1 parent 47d5ad7 commit 2b46bf2

File tree

1 file changed

+34
-16
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/_configuration

1 file changed

+34
-16
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,37 +345,54 @@ def _import_id_generator(id_generator_name: str) -> IdGenerator:
345345
raise RuntimeError(f"{id_generator_name} is not an IdGenerator")
346346

347347

348-
def _initialize_components(auto_instrumentation_version):
349-
trace_exporters, metric_exporters, log_exporters = _import_exporters(
350-
_get_exporter_names("traces"),
351-
_get_exporter_names("metrics"),
352-
_get_exporter_names("logs"),
348+
def _initialize_components(**kwargs):
349+
auto_instrumentation_version = kwargs.get("auto_instrumentation_version")
350+
# Could be trace_exporters or span_exporters
351+
span_exporter_names = kwargs.get("span_exporter_names")
352+
metric_exporter_names = kwargs.get("metric_exporter_names")
353+
log_exporter_names = kwargs.get("log_exporter_names")
354+
sampler_name = kwargs.get("sampler_name")
355+
# Could be attribute dict or Resource object
356+
resource_attributes = kwargs.get("resource_attributes")
357+
logging_enabled = kwargs.get("logging_enabled")
358+
# Could come before or after
359+
span_exporters, metric_exporters, log_exporters = _import_exporters(
360+
span_exporter_names + _get_exporter_names("traces"),
361+
metric_exporter_names + _get_exporter_names("metrics"),
362+
log_exporter_names + _get_exporter_names("logs"),
353363
)
354-
sampler_name = _get_sampler()
364+
if sampler_name is None:
365+
sampler_name = _get_sampler()
355366
sampler = _import_sampler(sampler_name)
356-
id_generator_name = _get_id_generator()
367+
if id_generator_name is None:
368+
id_generator_name = _get_id_generator()
357369
id_generator = _import_id_generator(id_generator_name)
358370
# if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name
359371
# from the env variable else defaults to "unknown_service"
360-
auto_resource = {}
372+
auto_resource_attributes = {}
373+
if resource_attributes is not None:
374+
auto_resource_attributes = resource_attributes
361375
# populate version if using auto-instrumentation
362376
if auto_instrumentation_version:
363-
auto_resource[
377+
auto_resource_attributes[
364378
ResourceAttributes.TELEMETRY_AUTO_VERSION
365379
] = auto_instrumentation_version
366-
resource = Resource.create(auto_resource)
380+
resource = Resource.create(auto_resource_attributes)
367381

368382
_init_tracing(
369-
exporters=trace_exporters,
383+
exporters=span_exporters,
370384
id_generator=id_generator,
371385
sampler=sampler,
372386
resource=resource,
373387
)
374388
_init_metrics(metric_exporters, resource)
375-
logging_enabled = os.getenv(
376-
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "false"
377-
)
378-
if logging_enabled.strip().lower() == "true":
389+
# This could also be paramaterized
390+
if logging_enabled is None:
391+
logging_enabled = os.getenv(
392+
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "false"
393+
).strip().lower() == "true"
394+
# Could be string or bool
395+
if logging_enabled:
379396
_init_logging(log_exporters, resource)
380397

381398

@@ -419,4 +436,5 @@ class _OTelSDKConfigurator(_BaseConfigurator):
419436
"""
420437

421438
def _configure(self, **kwargs):
422-
_initialize_components(kwargs.get("auto_instrumentation_version"))
439+
# _initialize_components(kwargs.get("auto_instrumentation_version"))
440+
_initialize_components(**kwargs)

0 commit comments

Comments
 (0)