Skip to content

Commit

Permalink
Verify custom resource attributes support (#32).
Browse files Browse the repository at this point in the history
Co-authored-by: p-pautov <37922380+p-pautov@users.noreply.github.com>
  • Loading branch information
jimf5 and p-pautov authored Dec 20, 2024
1 parent 1d25954 commit c9136f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
32 changes: 29 additions & 3 deletions tests/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
otel_trace on;
otel_service_name test_service;
{{ resource_attrs }}
server {
listen 127.0.0.1:18443 ssl;
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_context(client, trace_service, parent, path):

@pytest.mark.parametrize(
"nginx_config",
[({"interval": "200ms", "scheme": "http://"})],
[{"interval": "200ms", "scheme": "http://"}],
indirect=True,
)
@pytest.mark.parametrize("batch_count", [1, 3])
Expand All @@ -257,8 +257,34 @@ def test_batches(client, trace_service, batch_count):
assert len(trace_service.batches) == batch_count

for batch in trace_service.batches:
assert get_attr(batch[0].resource, "service.name") == "test_service"
assert (
get_attr(batch[0].resource, "service.name")
== "unknown_service:nginx"
)
assert len(batch[0].scope_spans[0].spans) == batch_size

time.sleep(0.3) # wait for +1 request to be flushed
trace_service.batches.clear()


@pytest.mark.parametrize(
"nginx_config",
[
{
"resource_attrs": """
otel_service_name "test_service";
otel_resource_attr my.name "my name";
otel_resource_attr my.service "my service";
""",
}
],
indirect=True,
)
def test_custom_resource_attributes(client, trace_service):
assert client.get("http://127.0.0.1:18080/ok").status_code == 200

batch = trace_service.get_batch()

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"
14 changes: 9 additions & 5 deletions tests/trace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ def Export(self, request, context):
self.batches.append(request.resource_spans)
return trace_service_pb2.ExportTracePartialSuccess()

def get_span(self):
def get_batch(self):
for _ in range(10):
if len(self.batches):
break
time.sleep(0.001)
assert len(self.batches) == 1
assert len(self.batches[0]) == 1
return self.batches.pop()[0]

assert len(self.batches) == 1, "No spans received"
span = self.batches[0][0].scope_spans[0].spans.pop()
self.batches.clear()
return span
def get_span(self):
batch = self.get_batch()
assert len(batch.scope_spans) == 1
assert len(batch.scope_spans[0].spans) == 1
return batch.scope_spans[0].spans.pop()


@pytest.fixture(scope="module")
Expand Down

0 comments on commit c9136f2

Please sign in to comment.