Skip to content

Commit

Permalink
Verify custom exporter headers support (#62).
Browse files Browse the repository at this point in the history
  • Loading branch information
p-pautov committed Dec 20, 2024
1 parent 1ea3439 commit a0103d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
25 changes: 25 additions & 0 deletions tests/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
interval {{ interval or "1ms" }};
batch_size 3;
batch_count 3;
{{ exporter_opts }}
}
otel_trace on;
Expand Down Expand Up @@ -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"
11 changes: 8 additions & 3 deletions tests/trace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand All @@ -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

Expand Down

0 comments on commit a0103d1

Please sign in to comment.