@@ -345,37 +345,54 @@ def _import_id_generator(id_generator_name: str) -> IdGenerator:
345
345
raise RuntimeError (f"{ id_generator_name } is not an IdGenerator" )
346
346
347
347
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" ),
353
363
)
354
- sampler_name = _get_sampler ()
364
+ if sampler_name is None :
365
+ sampler_name = _get_sampler ()
355
366
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 ()
357
369
id_generator = _import_id_generator (id_generator_name )
358
370
# if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name
359
371
# 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
361
375
# populate version if using auto-instrumentation
362
376
if auto_instrumentation_version :
363
- auto_resource [
377
+ auto_resource_attributes [
364
378
ResourceAttributes .TELEMETRY_AUTO_VERSION
365
379
] = auto_instrumentation_version
366
- resource = Resource .create (auto_resource )
380
+ resource = Resource .create (auto_resource_attributes )
367
381
368
382
_init_tracing (
369
- exporters = trace_exporters ,
383
+ exporters = span_exporters ,
370
384
id_generator = id_generator ,
371
385
sampler = sampler ,
372
386
resource = resource ,
373
387
)
374
388
_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 :
379
396
_init_logging (log_exporters , resource )
380
397
381
398
@@ -419,4 +436,5 @@ class _OTelSDKConfigurator(_BaseConfigurator):
419
436
"""
420
437
421
438
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