diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_client.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_client.py index 9c8cc5cdf3..684693bea0 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_client.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_client.py @@ -24,7 +24,9 @@ ) from opentelemetry.instrumentation.utils import is_instrumentation_enabled from opentelemetry.propagate import inject -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, +) from opentelemetry.trace.status import Status, StatusCode logger = logging.getLogger(__name__) @@ -34,7 +36,7 @@ def _unary_done_callback(span, code, details, response_hook): def callback(call): try: span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, + RPC_GRPC_STATUS_CODE, code.value[0], ) if code != grpc.StatusCode.OK: @@ -75,7 +77,7 @@ def propagate_trace_in_details(client_call_details: ClientCallDetails): def add_error_details_to_span(span, exc): if isinstance(exc, grpc.RpcError): span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, + RPC_GRPC_STATUS_CODE, exc.code().value[0], ) span.set_status( diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py index ba255ef3bf..73a7c16c08 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py @@ -16,7 +16,9 @@ import grpc.aio import wrapt -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, +) from ._server import OpenTelemetryServerInterceptor, _wrap_rpc_behavior from ._utilities import _server_status @@ -34,7 +36,7 @@ async def abort(self, code, details="", trailing_metadata=tuple()): self._self_code = code self._self_details = details self._self_active_span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0] + RPC_GRPC_STATUS_CODE, code.value[0] ) status = _server_status(code, details) self._self_active_span.set_status(status) @@ -44,7 +46,7 @@ def set_code(self, code): self._self_code = code details = self._self_details or code.value[1] self._self_active_span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0] + RPC_GRPC_STATUS_CODE, code.value[0] ) if code != grpc.StatusCode.OK: status = _server_status(code, details) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py index adc713678c..bbeb4ec1d9 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py @@ -31,7 +31,12 @@ from opentelemetry.instrumentation.utils import is_instrumentation_enabled from opentelemetry.propagate import inject from opentelemetry.propagators.textmap import Setter -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.trace.status import Status, StatusCode logger = logging.getLogger(__name__) @@ -87,10 +92,10 @@ def __init__( def _start_span(self, method, **kwargs): service, meth = method.lstrip("/").split("/", 1) attributes = { - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], - SpanAttributes.RPC_METHOD: meth, - SpanAttributes.RPC_SERVICE: service, + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], + RPC_METHOD: meth, + RPC_SERVICE: service, } return self._tracer.start_as_current_span( @@ -153,7 +158,7 @@ def _intercept(self, request, metadata, client_info, invoker): except Exception as exc: if isinstance(exc, grpc.RpcError): span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, + RPC_GRPC_STATUS_CODE, exc.code().value[0], ) span.set_status( @@ -211,9 +216,7 @@ def _intercept_server_stream( yield from invoker(request_or_iterator, metadata) except grpc.RpcError as err: span.set_status(Status(StatusCode.ERROR)) - span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, err.code().value[0] - ) + span.set_attribute(RPC_GRPC_STATUS_CODE, err.code().value[0]) raise err def intercept_stream( diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py index f63a12a25e..1a7d6ccc8b 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py @@ -30,7 +30,17 @@ from opentelemetry import trace from opentelemetry.context import attach, detach from opentelemetry.propagate import extract -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_IP, + NET_PEER_NAME, + NET_PEER_PORT, +) +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from ._utilities import _server_status @@ -122,9 +132,7 @@ def trailing_metadata(self): def abort(self, code, details): self._code = code self._details = details - self._active_span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0] - ) + self._active_span.set_attribute(RPC_GRPC_STATUS_CODE, code.value[0]) status = _server_status(code, details) self._active_span.set_status(status) return self._servicer_context.abort(code, details) @@ -151,9 +159,7 @@ def set_code(self, code): self._code = code # use details if we already have it, otherwise the status description details = self._details or code.value[1] - self._active_span.set_attribute( - SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0] - ) + self._active_span.set_attribute(RPC_GRPC_STATUS_CODE, code.value[0]) if code != grpc.StatusCode.OK: status = _server_status(code, details) self._active_span.set_status(status) @@ -212,8 +218,8 @@ def _start_span( ): # standard attributes attributes = { - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], } # if we have details about the call, split into service and method @@ -223,8 +229,8 @@ def _start_span( ) attributes.update( { - SpanAttributes.RPC_METHOD: method, - SpanAttributes.RPC_SERVICE: service, + RPC_METHOD: method, + RPC_SERVICE: service, } ) @@ -250,14 +256,14 @@ def _start_span( ip = unquote(ip) attributes.update( { - SpanAttributes.NET_PEER_IP: ip, - SpanAttributes.NET_PEER_PORT: port, + NET_PEER_IP: ip, + NET_PEER_PORT: port, } ) # other telemetry sources add this, so we will too if ip in ("[::1]", "127.0.0.1"): - attributes[SpanAttributes.NET_PEER_NAME] = "localhost" + attributes[NET_PEER_NAME] = "localhost" except IndexError: logger.warning( diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py index 4cd19da4af..850ad79661 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py @@ -26,7 +26,12 @@ ) from opentelemetry.instrumentation.utils import suppress_instrumentation from opentelemetry.propagate import get_global_textmap, set_global_textmap -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase @@ -121,12 +126,10 @@ async def test_unary_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -149,12 +152,10 @@ async def test_unary_stream(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -177,12 +178,10 @@ async def test_stream_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "ClientStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ClientStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -207,12 +206,10 @@ async def test_stream_stream(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "BidirectionalStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "BidirectionalStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py index 04a2c02476..e9565f8f8f 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py @@ -24,7 +24,16 @@ aio_server_interceptor, ) from opentelemetry.sdk import trace as trace_sdk -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_IP, + NET_PEER_NAME, +) +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode @@ -109,14 +118,12 @@ async def request(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -170,14 +177,12 @@ async def request(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -227,14 +232,12 @@ async def request(channel): self.assertSpanHasAttributes( parent_span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -275,14 +278,12 @@ async def request(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -334,14 +335,12 @@ async def request(channel): self.assertSpanHasAttributes( parent_span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -424,14 +423,12 @@ async def sequential_requests(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -487,14 +484,12 @@ async def concurrent_requests(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -549,14 +544,12 @@ async def request(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.INTERNAL.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.INTERNAL.value[0], }, ) @@ -615,12 +608,12 @@ async def request(channel): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.FAILED_PRECONDITION.value[ + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.FAILED_PRECONDITION.value[ 0 ], }, @@ -669,14 +662,12 @@ async def intercept_service( self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py index 5be0141c3b..e001d2ed57 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py @@ -29,7 +29,12 @@ from opentelemetry.instrumentation.utils import suppress_instrumentation from opentelemetry.propagate import get_global_textmap, set_global_textmap from opentelemetry.sdk.trace import Span as SdkSpan -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase @@ -135,12 +140,10 @@ def test_unary_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -161,12 +164,10 @@ def test_unary_stream(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -187,12 +188,10 @@ def test_stream_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "ClientStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ClientStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -215,12 +214,10 @@ def test_stream_stream(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "BidirectionalStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "BidirectionalStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py index 81e8d708f2..437175c4b2 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py @@ -29,7 +29,12 @@ ) from opentelemetry.instrumentation.utils import suppress_instrumentation from opentelemetry.propagate import get_global_textmap, set_global_textmap -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase @@ -137,12 +142,10 @@ def test_unary_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -281,12 +284,10 @@ def test_unary_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -464,12 +465,10 @@ def test_unary_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -490,12 +489,10 @@ def test_unary_stream(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -516,12 +513,10 @@ def test_stream_unary(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "ClientStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ClientStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -544,12 +539,10 @@ def test_stream_stream(self): self.assertSpanHasAttributes( span, { - SpanAttributes.RPC_METHOD: "BidirectionalStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "BidirectionalStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py index 013c283613..5f53b0a3ea 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py @@ -30,7 +30,16 @@ server_interceptor, ) from opentelemetry.sdk import trace as trace_sdk -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_IP, + NET_PEER_NAME, +) +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode @@ -82,8 +91,8 @@ def ServerStreamingMethod(self, request, context): class TestOpenTelemetryServerInterceptor(TestBase): net_peer_span_attributes = { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", } @contextlib.contextmanager @@ -137,12 +146,10 @@ def handler(request, context): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "handler", + RPC_SERVICE: "TestServicer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -203,12 +210,10 @@ def test_create_span(self): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -267,12 +272,10 @@ def SimpleMethod(self, request, context): parent_span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -322,12 +325,10 @@ def test_create_span_streaming(self): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -386,12 +387,10 @@ def ServerStreamingMethod(self, request, context): parent_span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "ServerStreamingMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "ServerStreamingMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -474,12 +473,10 @@ def handler(request, context): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "handler", + RPC_SERVICE: "TestServicer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -540,12 +537,10 @@ def handler(request, context): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "handler", + RPC_SERVICE: "TestServicer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -616,12 +611,10 @@ def unset_status_handler(request, context): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "error_status_handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.INTERNAL.value[ - 0 - ], + RPC_METHOD: "error_status_handler", + RPC_SERVICE: "TestServicer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.INTERNAL.value[0], }, ) @@ -644,10 +637,10 @@ def unset_status_handler(request, context): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "unset_status_handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.FAILED_PRECONDITION.value[ + RPC_METHOD: "unset_status_handler", + RPC_SERVICE: "TestServicer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.FAILED_PRECONDITION.value[ 0 ], }, @@ -693,12 +686,10 @@ def test_non_list_interceptors(self): span, { **self.net_peer_span_attributes, - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor_filter.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor_filter.py index 6a0081c4af..eb218b7985 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor_filter.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor_filter.py @@ -26,7 +26,16 @@ filters, server_interceptor, ) -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_IP, + NET_PEER_NAME, +) +from opentelemetry.semconv._incubating.attributes.rpc_attributes import ( + RPC_GRPC_STATUS_CODE, + RPC_METHOD, + RPC_SERVICE, + RPC_SYSTEM, +) from opentelemetry.test.test_base import TestBase from .protobuf.test_server_pb2 import Request, Response @@ -117,14 +126,12 @@ def handler(request, context): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "handler", + RPC_SERVICE: "TestServicer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, ) @@ -203,13 +210,11 @@ def test_create_span(self): self.assertSpanHasAttributes( span, { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "SimpleMethod", - SpanAttributes.RPC_SERVICE: "GRPCTestServer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], + NET_PEER_IP: "[::1]", + NET_PEER_NAME: "localhost", + RPC_METHOD: "SimpleMethod", + RPC_SERVICE: "GRPCTestServer", + RPC_SYSTEM: "grpc", + RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[0], }, )