diff --git a/tests/test_otel.py b/tests/test_otel.py index 11caa854..513c1f12 100644 --- a/tests/test_otel.py +++ b/tests/test_otel.py @@ -25,6 +25,8 @@ interval {{ interval or "1ms" }}; batch_size 3; batch_count 3; + + {{ exporter_opts }} } otel_trace on; @@ -288,3 +290,26 @@ def test_custom_resource_attributes(client, trace_service): assert get_attr(batch.resource, "service.name") == "test_service" assert get_attr(batch.resource, "my.name") == "my name" assert get_attr(batch.resource, "my.service") == "my service" + + +@pytest.mark.parametrize( + "nginx_config", + [ + { + "exporter_opts": """ + header X-API-TOKEN api.value; + header Authorization "Basic value"; + """, + } + ], + indirect=True, +) +@pytest.mark.parametrize("trace_service", ["skip_otelcol"], indirect=True) +def test_exporter_headers(client, trace_service): + assert client.get("http://127.0.0.1:18080/ok").status_code == 200 + + assert trace_service.get_span().name == "/ok" + + headers = dict(trace_service.last_metadata) + assert headers["x-api-token"] == "api.value" + assert headers["authorization"] == "Basic value" diff --git a/tests/trace_service.py b/tests/trace_service.py index 3b191a1d..f47b104c 100644 --- a/tests/trace_service.py +++ b/tests/trace_service.py @@ -12,6 +12,7 @@ class TraceService(trace_service_pb2_grpc.TraceServiceServicer): def Export(self, request, context): self.batches.append(request.resource_spans) + self.last_metadata = context.invocation_metadata() return trace_service_pb2.ExportTracePartialSuccess() def get_batch(self): @@ -31,13 +32,17 @@ def get_span(self): @pytest.fixture(scope="module") -def trace_service(pytestconfig, logger): +def trace_service(request, pytestconfig, logger): server = grpc.server(concurrent.futures.ThreadPoolExecutor()) trace_service = TraceService() trace_service_pb2_grpc.add_TraceServiceServicer_to_server( trace_service, server ) - listen_addr = f"127.0.0.1:{24317 if pytestconfig.option.otelcol else 14317}" + trace_service.use_otelcol = ( + pytestconfig.option.otelcol + and getattr(request, "param", "") != "skip_otelcol" + ) + listen_addr = f"127.0.0.1:{24317 if trace_service.use_otelcol else 14317}" server.add_insecure_port(listen_addr) logger.info(f"Starting trace service at {listen_addr}...") server.start() @@ -48,7 +53,7 @@ def trace_service(pytestconfig, logger): @pytest.fixture(scope="module") def otelcol(pytestconfig, testdir, logger, trace_service): - if pytestconfig.option.otelcol is None: + if not trace_service.use_otelcol: yield return