Skip to content

Commit 42e65e7

Browse files
change attributes
1 parent 3deb797 commit 42e65e7

4 files changed

Lines changed: 17 additions & 27 deletions

File tree

sentry_sdk/integrations/grpc/aio/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Callable, Union, AsyncIterable, Any
22

33
import sentry_sdk
4-
from sentry_sdk.consts import OP
4+
from sentry_sdk.consts import OP, SPANDATA
55
from sentry_sdk.integrations import DidNotEnable
66
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN
77
from sentry_sdk.tracing_utils import has_span_streaming_enabled
@@ -61,7 +61,6 @@ async def intercept_unary_unary(
6161
"sentry.origin": SPAN_ORIGIN,
6262
},
6363
) as span:
64-
span.set_attribute("type", "unary unary")
6564
span.set_attribute("rpc.method", method.decode())
6665

6766
client_call_details = (
@@ -72,7 +71,7 @@ async def intercept_unary_unary(
7271

7372
response = await continuation(client_call_details, request)
7473
status_code = await response.code()
75-
span.set_attribute("code", status_code.name)
74+
span.set_attribute(SPANDATA.RPC_RESPONSE_STATUS_CODE, status_code.name)
7675

7776
return response
7877
else:
@@ -120,8 +119,7 @@ async def intercept_unary_stream(
120119
"sentry.origin": SPAN_ORIGIN,
121120
},
122121
) as span:
123-
span.set_attribute("type", "unary stream")
124-
span.set_attribute("rpc.method", method.decode())
122+
span.set_attribute(SPANDATA.RPC_METHOD, method.decode())
125123

126124
client_call_details = (
127125
self._update_client_call_details_metadata_from_scope(
@@ -130,8 +128,6 @@ async def intercept_unary_stream(
130128
)
131129

132130
response = await continuation(client_call_details, request)
133-
# status_code = await response.code()
134-
# span.set_data("code", status_code)
135131

136132
return response
137133
else:

sentry_sdk/integrations/grpc/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sentry_sdk
2-
from sentry_sdk.consts import OP
2+
from sentry_sdk.consts import OP, SPANDATA
33
from sentry_sdk.integrations import DidNotEnable
44
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN
55
from sentry_sdk.tracing_utils import has_span_streaming_enabled
@@ -41,8 +41,7 @@ def intercept_unary_unary(
4141
"sentry.origin": SPAN_ORIGIN,
4242
},
4343
) as span:
44-
span.set_attribute("type", "unary unary")
45-
span.set_attribute("method", method)
44+
span.set_attribute(SPANDATA.RPC_METHOD, method)
4645

4746
client_call_details = (
4847
self._update_client_call_details_metadata_from_scope(
@@ -51,7 +50,9 @@ def intercept_unary_unary(
5150
)
5251

5352
response = continuation(client_call_details, request)
54-
span.set_attribute("code", response.code().name)
53+
span.set_attribute(
54+
SPANDATA.RPC_RESPONSE_STATUS_CODE, response.code().name
55+
)
5556

5657
return response
5758
else:
@@ -93,8 +94,7 @@ def intercept_unary_stream(
9394
"sentry.origin": SPAN_ORIGIN,
9495
},
9596
) as span:
96-
span.set_attribute("type", "unary stream")
97-
span.set_attribute("method", method)
97+
span.set_attribute(SPANDATA.RPC_METHOD, method)
9898

9999
client_call_details = (
100100
self._update_client_call_details_metadata_from_scope(

tests/integrations/grpc/test_grpc.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ def test_grpc_client_starts_span(
308308
)
309309
assert span["attributes"] == ApproxDict(
310310
{
311-
"type": "unary unary",
312-
"method": "/grpc_test_server.gRPCTestService/TestServe",
311+
"rpc.method": "/grpc_test_server.gRPCTestService/TestServe",
313312
"sentry.environment": mock.ANY,
314313
"sentry.op": "grpc.client",
315314
"sentry.origin": "auto.grpc.grpc",
@@ -321,7 +320,7 @@ def test_grpc_client_starts_span(
321320
"server.address": mock.ANY,
322321
"thread.id": mock.ANY,
323322
"thread.name": mock.ANY,
324-
"code": "OK",
323+
"rpc.response.status_code": "OK",
325324
}
326325
)
327326
else:
@@ -393,8 +392,7 @@ def test_grpc_client_unary_stream_starts_span(
393392
)
394393
assert span["attributes"] == ApproxDict(
395394
{
396-
"type": "unary stream",
397-
"method": "/grpc_test_server.gRPCTestService/TestUnaryStream",
395+
"rpc.method": "/grpc_test_server.gRPCTestService/TestUnaryStream",
398396
"sentry.environment": mock.ANY,
399397
"sentry.op": "grpc.client",
400398
"sentry.origin": "auto.grpc.grpc",
@@ -488,8 +486,7 @@ def test_grpc_client_other_interceptor(
488486
)
489487
assert span["attributes"] == ApproxDict(
490488
{
491-
"type": "unary unary",
492-
"method": "/grpc_test_server.gRPCTestService/TestServe",
489+
"rpc.method": "/grpc_test_server.gRPCTestService/TestServe",
493490
"sentry.environment": mock.ANY,
494491
"sentry.op": "grpc.client",
495492
"sentry.origin": "auto.grpc.grpc",
@@ -501,7 +498,7 @@ def test_grpc_client_other_interceptor(
501498
"server.address": mock.ANY,
502499
"thread.id": mock.ANY,
503500
"thread.name": mock.ANY,
504-
"code": "OK",
501+
"rpc.response.status_code": "OK",
505502
}
506503
)
507504
else:
@@ -576,9 +573,8 @@ def test_prevent_dual_client_interceptor(
576573
)
577574
assert span["attributes"] == ApproxDict(
578575
{
579-
"type": "unary unary",
580-
"method": "/grpc_test_server.gRPCTestService/TestServe",
581-
"code": "OK",
576+
"rpc.method": "/grpc_test_server.gRPCTestService/TestServe",
577+
"rpc.response.status_code": "OK",
582578
}
583579
)
584580
else:

tests/integrations/grpc/test_grpc_aio.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ async def test_grpc_client_starts_span(
333333
)
334334
assert span["attributes"] == ApproxDict(
335335
{
336-
"type": "unary unary",
337336
"rpc.method": "/grpc_test_server.gRPCTestService/TestServe",
338337
"sentry.environment": mock.ANY,
339338
"sentry.op": "grpc.client",
@@ -346,7 +345,7 @@ async def test_grpc_client_starts_span(
346345
"server.address": mock.ANY,
347346
"thread.id": mock.ANY,
348347
"thread.name": mock.ANY,
349-
"code": "OK",
348+
"rpc.response.status_code": "OK",
350349
}
351350
)
352351
else:
@@ -409,7 +408,6 @@ async def test_grpc_client_unary_stream_starts_span(
409408
)
410409
assert span["attributes"] == ApproxDict(
411410
{
412-
"type": "unary stream",
413411
"rpc.method": "/grpc_test_server.gRPCTestService/TestUnaryStream",
414412
"sentry.environment": mock.ANY,
415413
"sentry.op": "grpc.client",

0 commit comments

Comments
 (0)