diff --git a/packages/service-library/requirements/_base.in b/packages/service-library/requirements/_base.in index 4e4ecd929e4f..5a51d883b74b 100644 --- a/packages/service-library/requirements/_base.in +++ b/packages/service-library/requirements/_base.in @@ -30,3 +30,4 @@ repro-zipfile tenacity toolz tqdm +yarl diff --git a/packages/service-library/requirements/_base.txt b/packages/service-library/requirements/_base.txt index 4ed45283e9e9..7bfebd08206b 100644 --- a/packages/service-library/requirements/_base.txt +++ b/packages/service-library/requirements/_base.txt @@ -274,6 +274,7 @@ wrapt==1.16.0 # opentelemetry-instrumentation-redis yarl==1.12.1 # via + # -r requirements/_base.in # aio-pika # aiohttp # aiormq diff --git a/packages/service-library/src/servicelib/aiohttp/tracing.py b/packages/service-library/src/servicelib/aiohttp/tracing.py index 3da3b28e3b35..199f48369769 100644 --- a/packages/service-library/src/servicelib/aiohttp/tracing.py +++ b/packages/service-library/src/servicelib/aiohttp/tracing.py @@ -20,6 +20,7 @@ from opentelemetry.sdk.trace.export import BatchSpanProcessor from servicelib.logging_utils import log_context from settings_library.tracing import TracingSettings +from yarl import URL _logger = logging.getLogger(__name__) try: @@ -54,7 +55,7 @@ def setup_tracing( """ _ = app opentelemetry_collector_endpoint = ( - tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT + f"{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}" ) opentelemetry_collector_port = tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_PORT if not opentelemetry_collector_endpoint and not opentelemetry_collector_port: @@ -72,9 +73,8 @@ def setup_tracing( resource = Resource(attributes={"service.name": service_name}) trace.set_tracer_provider(TracerProvider(resource=resource)) tracer_provider: trace.TracerProvider = trace.get_tracer_provider() - tracing_destination: str = ( - f"{opentelemetry_collector_endpoint}:{opentelemetry_collector_port}/v1/traces" - ) + + tracing_destination: str = f"{URL(opentelemetry_collector_endpoint).with_port(opentelemetry_collector_port).with_path('/v1/traces')}" _logger.info( "Trying to connect service %s to tracing collector at %s.", diff --git a/packages/service-library/src/servicelib/fastapi/tracing.py b/packages/service-library/src/servicelib/fastapi/tracing.py index 36e9b06fa122..ee0258d93f42 100644 --- a/packages/service-library/src/servicelib/fastapi/tracing.py +++ b/packages/service-library/src/servicelib/fastapi/tracing.py @@ -17,6 +17,7 @@ from opentelemetry.sdk.trace.export import BatchSpanProcessor from servicelib.logging_utils import log_context from settings_library.tracing import TracingSettings +from yarl import URL _logger = logging.getLogger(__name__) @@ -75,7 +76,13 @@ def setup_tracing( trace.set_tracer_provider(TracerProvider(resource=resource)) global_tracer_provider = trace.get_tracer_provider() assert isinstance(global_tracer_provider, TracerProvider) # nosec - tracing_destination: str = f"{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}:{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_PORT}/v1/traces" + + opentelemetry_collector_endpoint: str = ( + f"{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}" + ) + + tracing_destination: str = f"{URL(opentelemetry_collector_endpoint).with_port(tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_PORT).with_path('/v1/traces')}" + _logger.info( "Trying to connect service %s to opentelemetry tracing collector at %s.", service_name,