Use constants from semconv (#9626)

This commit is contained in:
Lauri Tulmin 2023-10-09 14:31:48 +03:00 committed by GitHub
parent 4add634b95
commit 432dc54de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 29 deletions

View File

@ -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() {}
}

View File

@ -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()) {

View File

@ -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);