Skip to content

Commit 9dc4dc2

Browse files
committed
Verify custom exporter headers support (#62).
1 parent a45a594 commit 9dc4dc2

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

tests/test_otel.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
interval {{ interval or "1ms" }};
2626
batch_size 3;
2727
batch_count 3;
28+
29+
{{ exporter_opts }}
2830
}
2931
3032
otel_trace on;
@@ -288,3 +290,26 @@ def test_custom_resource_attributes(client, trace_service):
288290
assert get_attr(batch.resource, "service.name") == "test_service"
289291
assert get_attr(batch.resource, "my.name") == "my name"
290292
assert get_attr(batch.resource, "my.service") == "my service"
293+
294+
295+
@pytest.mark.parametrize(
296+
"nginx_config",
297+
[
298+
{
299+
"exporter_opts": """
300+
header X-API-TOKEN api.value;
301+
header Authorization "Basic value";
302+
""",
303+
}
304+
],
305+
indirect=True,
306+
)
307+
@pytest.mark.parametrize("trace_service", ["skip_otelcol"], indirect=True)
308+
def test_exporter_headers(client, trace_service):
309+
assert client.get("http://127.0.0.1:18080/ok").status_code == 200
310+
311+
assert trace_service.get_span().name == "/ok"
312+
313+
headers = dict(trace_service.last_metadata)
314+
assert headers["x-api-token"] == "api.value"
315+
assert headers["authorization"] == "Basic value"

tests/trace_service.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TraceService(trace_service_pb2_grpc.TraceServiceServicer):
1212

1313
def Export(self, request, context):
1414
self.batches.append(request.resource_spans)
15+
self.last_metadata = context.invocation_metadata()
1516
return trace_service_pb2.ExportTracePartialSuccess()
1617

1718
def get_batch(self):
@@ -31,13 +32,17 @@ def get_span(self):
3132

3233

3334
@pytest.fixture(scope="module")
34-
def trace_service(pytestconfig, logger):
35+
def trace_service(request, pytestconfig, logger):
3536
server = grpc.server(concurrent.futures.ThreadPoolExecutor())
3637
trace_service = TraceService()
3738
trace_service_pb2_grpc.add_TraceServiceServicer_to_server(
3839
trace_service, server
3940
)
40-
listen_addr = f"127.0.0.1:{24317 if pytestconfig.option.otelcol else 14317}"
41+
trace_service.use_otelcol = (
42+
pytestconfig.option.otelcol
43+
and getattr(request, "param", "") != "skip_otelcol"
44+
)
45+
listen_addr = f"127.0.0.1:{24317 if trace_service.use_otelcol else 14317}"
4146
server.add_insecure_port(listen_addr)
4247
logger.info(f"Starting trace service at {listen_addr}...")
4348
server.start()
@@ -48,7 +53,7 @@ def trace_service(pytestconfig, logger):
4853

4954
@pytest.fixture(scope="module")
5055
def otelcol(pytestconfig, testdir, logger, trace_service):
51-
if pytestconfig.option.otelcol is None:
56+
if not trace_service.use_otelcol:
5257
yield
5358
return
5459

0 commit comments

Comments
 (0)