Verify custom resource attributes support (#32).

Co-authored-by: p-pautov <37922380+p-pautov@users.noreply.github.com>
This commit is contained in:
Eugene 2024-12-19 17:53:38 -08:00 committed by GitHub
parent 1d25954274
commit c9136f2ec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 8 deletions

View file

@ -28,7 +28,7 @@ http {
} }
otel_trace on; otel_trace on;
otel_service_name test_service; {{ resource_attrs }}
server { server {
listen 127.0.0.1:18443 ssl; listen 127.0.0.1:18443 ssl;
@ -240,7 +240,7 @@ def test_context(client, trace_service, parent, path):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"nginx_config", "nginx_config",
[({"interval": "200ms", "scheme": "http://"})], [{"interval": "200ms", "scheme": "http://"}],
indirect=True, indirect=True,
) )
@pytest.mark.parametrize("batch_count", [1, 3]) @pytest.mark.parametrize("batch_count", [1, 3])
@ -257,8 +257,34 @@ def test_batches(client, trace_service, batch_count):
assert len(trace_service.batches) == batch_count assert len(trace_service.batches) == batch_count
for batch in trace_service.batches: 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 assert len(batch[0].scope_spans[0].spans) == batch_size
time.sleep(0.3) # wait for +1 request to be flushed time.sleep(0.3) # wait for +1 request to be flushed
trace_service.batches.clear() 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"

View file

@ -14,16 +14,20 @@ class TraceService(trace_service_pb2_grpc.TraceServiceServicer):
self.batches.append(request.resource_spans) self.batches.append(request.resource_spans)
return trace_service_pb2.ExportTracePartialSuccess() return trace_service_pb2.ExportTracePartialSuccess()
def get_span(self): def get_batch(self):
for _ in range(10): for _ in range(10):
if len(self.batches): if len(self.batches):
break break
time.sleep(0.001) 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" def get_span(self):
span = self.batches[0][0].scope_spans[0].spans.pop() batch = self.get_batch()
self.batches.clear() assert len(batch.scope_spans) == 1
return span assert len(batch.scope_spans[0].spans) == 1
return batch.scope_spans[0].spans.pop()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")