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.Scope;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
|
import io.opentelemetry.semconv.SemanticAttributes;
|
||||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||||
|
|
||||||
final class TracingClientInterceptor implements ClientInterceptor {
|
final class TracingClientInterceptor implements ClientInterceptor {
|
||||||
|
@ -110,9 +111,9 @@ final class TracingClientInterceptor implements ClientInterceptor {
|
||||||
Span span = Span.fromContext(context);
|
Span span = Span.fromContext(context);
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
Attributes.of(
|
Attributes.of(
|
||||||
GrpcHelper.MESSAGE_TYPE,
|
SemanticAttributes.MESSAGE_TYPE,
|
||||||
"SENT",
|
SemanticAttributes.MessageTypeValues.SENT,
|
||||||
GrpcHelper.MESSAGE_ID,
|
SemanticAttributes.MESSAGE_ID,
|
||||||
MESSAGE_ID_UPDATER.incrementAndGet(this));
|
MESSAGE_ID_UPDATER.incrementAndGet(this));
|
||||||
span.addEvent("message", attributes);
|
span.addEvent("message", attributes);
|
||||||
}
|
}
|
||||||
|
@ -140,9 +141,9 @@ final class TracingClientInterceptor implements ClientInterceptor {
|
||||||
Span span = Span.fromContext(context);
|
Span span = Span.fromContext(context);
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
Attributes.of(
|
Attributes.of(
|
||||||
GrpcHelper.MESSAGE_TYPE,
|
SemanticAttributes.MESSAGE_TYPE,
|
||||||
"RECEIVED",
|
SemanticAttributes.MessageTypeValues.RECEIVED,
|
||||||
GrpcHelper.MESSAGE_ID,
|
SemanticAttributes.MESSAGE_ID,
|
||||||
MESSAGE_ID_UPDATER.incrementAndGet(TracingClientCall.this));
|
MESSAGE_ID_UPDATER.incrementAndGet(TracingClientCall.this));
|
||||||
span.addEvent("message", attributes);
|
span.addEvent("message", attributes);
|
||||||
try (Scope ignored = context.makeCurrent()) {
|
try (Scope ignored = context.makeCurrent()) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import io.opentelemetry.api.trace.Span;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
|
import io.opentelemetry.semconv.SemanticAttributes;
|
||||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||||
|
|
||||||
final class TracingServerInterceptor implements ServerInterceptor {
|
final class TracingServerInterceptor implements ServerInterceptor {
|
||||||
|
@ -91,9 +92,9 @@ final class TracingServerInterceptor implements ServerInterceptor {
|
||||||
Span span = Span.fromContext(context);
|
Span span = Span.fromContext(context);
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
Attributes.of(
|
Attributes.of(
|
||||||
GrpcHelper.MESSAGE_TYPE,
|
SemanticAttributes.MESSAGE_TYPE,
|
||||||
"SENT",
|
SemanticAttributes.MessageTypeValues.SENT,
|
||||||
GrpcHelper.MESSAGE_ID,
|
SemanticAttributes.MESSAGE_ID,
|
||||||
MESSAGE_ID_UPDATER.incrementAndGet(this));
|
MESSAGE_ID_UPDATER.incrementAndGet(this));
|
||||||
span.addEvent("message", attributes);
|
span.addEvent("message", attributes);
|
||||||
}
|
}
|
||||||
|
@ -122,12 +123,11 @@ final class TracingServerInterceptor implements ServerInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(REQUEST message) {
|
public void onMessage(REQUEST message) {
|
||||||
// TODO(anuraaga): Restore
|
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
Attributes.of(
|
Attributes.of(
|
||||||
GrpcHelper.MESSAGE_TYPE,
|
SemanticAttributes.MESSAGE_TYPE,
|
||||||
"RECEIVED",
|
SemanticAttributes.MessageTypeValues.RECEIVED,
|
||||||
GrpcHelper.MESSAGE_ID,
|
SemanticAttributes.MESSAGE_ID,
|
||||||
MESSAGE_ID_UPDATER.incrementAndGet(TracingServerCall.this));
|
MESSAGE_ID_UPDATER.incrementAndGet(TracingServerCall.this));
|
||||||
Span.fromContext(context).addEvent("message", attributes);
|
Span.fromContext(context).addEvent("message", attributes);
|
||||||
delegate().onMessage(message);
|
delegate().onMessage(message);
|
||||||
|
|
Loading…
Reference in New Issue