Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify custom resource attributes support (#32). #82

Merged
merged 9 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 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;
{{ res_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,37 @@ 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",
[
{
"res_attrs": """
p-pautov marked this conversation as resolved.
Show resolved Hide resolved
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

trace_service.wait_one_batch()
p-pautov marked this conversation as resolved.
Show resolved Hide resolved

for batch in trace_service.batches:
assert get_attr(batch[0].resource, "service.name") == "test_service"
assert get_attr(batch[0].resource, "my.name") == "my name"
assert get_attr(batch[0].resource, "my.service") == "my service"

trace_service.batches.clear()
6 changes: 4 additions & 2 deletions tests/trace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ def Export(self, request, context):
self.batches.append(request.resource_spans)
return trace_service_pb2.ExportTracePartialSuccess()

def get_span(self):
def wait_one_batch(self):
for _ in range(10):
if len(self.batches):
break
time.sleep(0.001)

assert len(self.batches) == 1, "No spans received"
p-pautov marked this conversation as resolved.
Show resolved Hide resolved

def get_span(self):
self.wait_one_batch()
span = self.batches[0][0].scope_spans[0].spans.pop()
self.batches.clear()
return span
Expand Down