Skip to content

Commit af42bf3

Browse files
Use AttributeKey
1 parent 74aa1be commit af42bf3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
final class TracingClientInterceptor implements ClientInterceptor {
2828

29+
private static final AttributeKey<Long> GRPC_MESSAGES_RECEIVED =
30+
AttributeKey.longKey("grpc.messages.received");
31+
private static final AttributeKey<Long> GRPC_MESSAGES_SENT =
32+
AttributeKey.longKey("grpc.messages.sent");
2933
// copied from MessageIncubatingAttributes
3034
private static final AttributeKey<Long> MESSAGE_ID = AttributeKey.longKey("message.id");
3135
private static final AttributeKey<String> MESSAGE_TYPE = AttributeKey.stringKey("message.type");
@@ -171,9 +175,9 @@ public void onClose(Status status, Metadata trailers) {
171175
if (captureExperimentalSpanAttributes) {
172176
Span span = Span.fromContext(context);
173177
span.setAttribute(
174-
"grpc.messages.received", RECEIVED_MESSAGE_ID_UPDATER.get(TracingClientCall.this));
178+
GRPC_MESSAGES_RECEIVED, RECEIVED_MESSAGE_ID_UPDATER.get(TracingClientCall.this));
175179
span.setAttribute(
176-
"grpc.messages.sent", SENT_MESSAGE_ID_UPDATER.get(TracingClientCall.this));
180+
GRPC_MESSAGES_SENT, SENT_MESSAGE_ID_UPDATER.get(TracingClientCall.this));
177181
}
178182
instrumenter.end(context, request, status, status.getCause());
179183
try (Scope ignored = parentContext.makeCurrent()) {

instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingServerInterceptor.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
final class TracingServerInterceptor implements ServerInterceptor {
2727

28+
private static final AttributeKey<Boolean> GRPC_CANCELED =
29+
AttributeKey.booleanKey("grpc.canceled");
30+
private static final AttributeKey<Long> GRPC_MESSAGES_RECEIVED =
31+
AttributeKey.longKey("grpc.messages.received");
32+
private static final AttributeKey<Long> GRPC_MESSAGES_SENT =
33+
AttributeKey.longKey("grpc.messages.sent");
2834
// copied from MessageIncubatingAttributes
2935
private static final AttributeKey<Long> MESSAGE_ID = AttributeKey.longKey("message.id");
3036
private static final AttributeKey<String> MESSAGE_TYPE = AttributeKey.stringKey("message.type");
@@ -151,11 +157,11 @@ private void end(Context context, GrpcRequest request, Status response, Throwabl
151157
if (captureExperimentalSpanAttributes) {
152158
Span span = Span.fromContext(context);
153159
span.setAttribute(
154-
"grpc.messages.received", RECEIVED_MESSAGE_ID_UPDATER.get(TracingServerCall.this));
160+
GRPC_MESSAGES_RECEIVED, RECEIVED_MESSAGE_ID_UPDATER.get(TracingServerCall.this));
155161
span.setAttribute(
156-
"grpc.messages.sent", SENT_MESSAGE_ID_UPDATER.get(TracingServerCall.this));
162+
GRPC_MESSAGES_SENT, SENT_MESSAGE_ID_UPDATER.get(TracingServerCall.this));
157163
if (Status.CANCELLED.equals(status)) {
158-
span.setAttribute("grpc.canceled", true);
164+
span.setAttribute(GRPC_CANCELED, true);
159165
}
160166
}
161167
instrumenter.end(context, request, response, error);

0 commit comments

Comments
 (0)