Use constants from semconv (#9626)
This commit is contained in:
parent
4add634b95
commit
432dc54de8
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.grpc.v1_6;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
|
||||
final class GrpcHelper {
|
||||
|
||||
static final AttributeKey<String> MESSAGE_TYPE = AttributeKey.stringKey("message.type");
|
||||
static final AttributeKey<Long> MESSAGE_ID = AttributeKey.longKey("message.id");
|
||||
|
||||
private GrpcHelper() {}
|
||||
}
|
|
@ -21,6 +21,7 @@ import io.opentelemetry.context.Context;
|
|||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||
|
||||
final class TracingClientInterceptor implements ClientInterceptor {
|
||||
|
@ -110,9 +111,9 @@ final class TracingClientInterceptor implements ClientInterceptor {
|
|||
Span span = Span.fromContext(context);
|
||||
Attributes attributes =
|
||||
Attributes.of(
|
||||
GrpcHelper.MESSAGE_TYPE,
|
||||
"SENT",
|
||||
GrpcHelper.MESSAGE_ID,
|
||||
SemanticAttributes.MESSAGE_TYPE,
|
||||
SemanticAttributes.MessageTypeValues.SENT,
|
||||
SemanticAttributes.MESSAGE_ID,
|
||||
MESSAGE_ID_UPDATER.incrementAndGet(this));
|
||||
span.addEvent("message", attributes);
|
||||
}
|
||||
|
@ -140,9 +141,9 @@ final class TracingClientInterceptor implements ClientInterceptor {
|
|||
Span span = Span.fromContext(context);
|
||||
Attributes attributes =
|
||||
Attributes.of(
|
||||
GrpcHelper.MESSAGE_TYPE,
|
||||
"RECEIVED",
|
||||
GrpcHelper.MESSAGE_ID,
|
||||
SemanticAttributes.MESSAGE_TYPE,
|
||||
SemanticAttributes.MessageTypeValues.RECEIVED,
|
||||
SemanticAttributes.MESSAGE_ID,
|
||||
MESSAGE_ID_UPDATER.incrementAndGet(TracingClientCall.this));
|
||||
span.addEvent("message", attributes);
|
||||
try (Scope ignored = context.makeCurrent()) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import io.opentelemetry.api.trace.Span;
|
|||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||
|
||||
final class TracingServerInterceptor implements ServerInterceptor {
|
||||
|
@ -91,9 +92,9 @@ final class TracingServerInterceptor implements ServerInterceptor {
|
|||
Span span = Span.fromContext(context);
|
||||
Attributes attributes =
|
||||
Attributes.of(
|
||||
GrpcHelper.MESSAGE_TYPE,
|
||||
"SENT",
|
||||
GrpcHelper.MESSAGE_ID,
|
||||
SemanticAttributes.MESSAGE_TYPE,
|
||||
SemanticAttributes.MessageTypeValues.SENT,
|
||||
SemanticAttributes.MESSAGE_ID,
|
||||
MESSAGE_ID_UPDATER.incrementAndGet(this));
|
||||
span.addEvent("message", attributes);
|
||||
}
|
||||
|
@ -122,12 +123,11 @@ final class TracingServerInterceptor implements ServerInterceptor {
|
|||
|
||||
@Override
|
||||
public void onMessage(REQUEST message) {
|
||||
// TODO(anuraaga): Restore
|
||||
Attributes attributes =
|
||||
Attributes.of(
|
||||
GrpcHelper.MESSAGE_TYPE,
|
||||
"RECEIVED",
|
||||
GrpcHelper.MESSAGE_ID,
|
||||
SemanticAttributes.MESSAGE_TYPE,
|
||||
SemanticAttributes.MessageTypeValues.RECEIVED,
|
||||
SemanticAttributes.MESSAGE_ID,
|
||||
MESSAGE_ID_UPDATER.incrementAndGet(TracingServerCall.this));
|
||||
Span.fromContext(context).addEvent("message", attributes);
|
||||
delegate().onMessage(message);
|
||||
|
|
Loading…
Reference in New Issue