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 57452f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 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,25 @@ 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,
)
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"
1 change: 1 addition & 0 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 Down

0 comments on commit 57452f7

Please sign in to comment.