Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datadog.trace.api.datastreams.DataStreamsTags;
import datadog.trace.api.naming.SpanNaming;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
Expand Down Expand Up @@ -116,6 +117,7 @@ public AgentSpan onClose(final AgentSpan span, final Status status) {

span.setTag("status.code", status.getCode().name());
span.setTag("grpc.status.code", status.getCode().name());
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
span.setTag("status.description", status.getDescription());

// TODO why is there a mismatch between client / server for calling the onError method?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datadog.trace.api.naming.SpanNaming;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import datadog.trace.bootstrap.instrumentation.decorator.ServerDecorator;
Expand Down Expand Up @@ -97,6 +98,7 @@ public <RespT, ReqT> AgentSpan onCall(final AgentSpan span, ServerCall<ReqT, Res
public AgentSpan onStatus(final AgentSpan span, final Status status) {
span.setTag("status.code", status.getCode().name());
span.setTag("grpc.status.code", status.getCode().name());
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
span.setTag("status.description", status.getDescription());
return span.setError(
SERVER_ERROR_STATUSES.get(status.getCode().value()), ErrorPriorities.HTTP_SERVER_DECORATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.linecorp.armeria.server.grpc.GrpcService
import com.linecorp.armeria.testing.junit4.server.ServerRule
import datadog.trace.agent.test.naming.VersionedNamingTestBase
import datadog.trace.api.DDSpanTypes
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
import datadog.trace.bootstrap.instrumentation.api.Tags
import example.GreeterGrpc
import example.Helloworld
Expand Down Expand Up @@ -178,6 +179,7 @@ abstract class ArmeriaGrpcStreamingTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
"request.type" "example.Helloworld\$Response"
"response.type" "example.Helloworld\$Response"
peerServiceFrom(Tags.RPC_SERVICE)
Expand Down Expand Up @@ -215,6 +217,7 @@ abstract class ArmeriaGrpcStreamingTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
defaultTags(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import datadog.trace.api.gateway.RequestContext
import datadog.trace.api.gateway.RequestContextSlot
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.core.datastreams.StatsGroup
import datadog.trace.instrumentation.armeria.grpc.server.GrpcExtractAdapter
Expand Down Expand Up @@ -182,6 +183,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
if ({ isDataStreamsEnabled() }) {
Expand Down Expand Up @@ -221,6 +223,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
if ({ isDataStreamsEnabled() }) {
"$DDTags.PATHWAY_HASH" { String }
}
Expand Down Expand Up @@ -319,6 +322,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "${status.code.name()}"
"grpc.status.code" "${status.code.name()}"
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
"status.description" description
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
Expand All @@ -343,6 +347,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "${status.code.name()}"
"grpc.status.code" "${status.code.name()}"
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
"status.description" description
"canceled" { true } // 1.0.0 handles cancellation incorrectly so accesting any value
if (status.cause != null) {
Expand Down Expand Up @@ -432,6 +437,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" status.code.name()
"grpc.status.code" status.code.name()
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
if (status.description != null) {
"status.description" status.description
}
Expand Down Expand Up @@ -459,6 +465,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
errorTags error.class, error.message
"status.code" "${status.code.name()}"
"grpc.status.code" "${status.code.name()}"
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
"status.description" { it == null || String}
"canceled" { true } // 1.0.0 handles cancellation incorrectly so accesting any value
if ({ isDataStreamsEnabled() }) {
Expand Down Expand Up @@ -574,6 +581,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
if ({ isDataStreamsEnabled() }) {
"$DDTags.PATHWAY_HASH" { String }
}
Expand Down Expand Up @@ -650,6 +658,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
if ({ isDataStreamsEnabled() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import datadog.trace.api.config.GeneralConfig
import datadog.trace.api.config.TraceInstrumentationConfig
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.core.DDSpan
import datadog.trace.core.datastreams.StatsGroup
Expand Down Expand Up @@ -284,6 +285,7 @@ abstract class PubSubTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" { String }
"status.code" { String }
"grpc.status.code" { String }
"$InstrumentationTags.GRPC_STATUS_CODE" { Integer }
if ({ isDataStreamsEnabled() }) {
"$DDTags.PATHWAY_HASH" { String }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import datadog.trace.api.datastreams.DataStreamsContext;
import datadog.trace.api.naming.SpanNaming;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
Expand Down Expand Up @@ -116,6 +117,7 @@ public <C> void injectContext(Context context, final C request, CarrierSetter<C>
public AgentSpan onClose(final AgentSpan span, final Status status) {
span.setTag("status.code", status.getCode().name());
span.setTag("grpc.status.code", status.getCode().name());
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
span.setTag("status.description", status.getDescription());

// TODO why is there a mismatch between client / server for calling the onError method?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datadog.trace.api.naming.SpanNaming;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import datadog.trace.bootstrap.instrumentation.decorator.ServerDecorator;
Expand Down Expand Up @@ -98,6 +99,7 @@ public <RespT, ReqT> AgentSpan onCall(final AgentSpan span, ServerCall<ReqT, Res
public AgentSpan onStatus(final AgentSpan span, final Status status) {
span.setTag("status.code", status.getCode().name());
span.setTag("grpc.status.code", status.getCode().name());
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
span.setTag("status.description", status.getDescription());
return span.setError(
SERVER_ERROR_STATUSES.get(status.getCode().value()), ErrorPriorities.HTTP_SERVER_DECORATOR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.google.common.util.concurrent.MoreExecutors
import datadog.trace.agent.test.naming.VersionedNamingTestBase
import datadog.trace.api.DDSpanTypes
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
import datadog.trace.bootstrap.instrumentation.api.Tags
import example.GreeterGrpc
import example.Helloworld
Expand Down Expand Up @@ -162,6 +163,7 @@ abstract class GrpcStreamingTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
"request.type" "example.Helloworld\$Response"
"response.type" "example.Helloworld\$Response"
peerServiceFrom(Tags.RPC_SERVICE)
Expand Down Expand Up @@ -198,6 +200,7 @@ abstract class GrpcStreamingTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
defaultTags(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import datadog.trace.api.gateway.RequestContext
import datadog.trace.api.gateway.RequestContextSlot
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.core.datastreams.StatsGroup
import datadog.trace.instrumentation.grpc.server.GrpcExtractAdapter
Expand Down Expand Up @@ -173,6 +174,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.PEER_PORT" server.port
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
if ({ isDataStreamsEnabled() }) {
Expand Down Expand Up @@ -212,6 +214,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
if ({ isDataStreamsEnabled() }) {
"$DDTags.PATHWAY_HASH" { String }
}
Expand Down Expand Up @@ -317,6 +320,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "${status.code.name()}"
"grpc.status.code" "${status.code.name()}"
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
"status.description" description
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
Expand All @@ -341,6 +345,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "${status.code.name()}"
"grpc.status.code" "${status.code.name()}"
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
"status.description" description
if (status.cause != null) {
errorTags status.cause.class, status.cause.message
Expand Down Expand Up @@ -424,6 +429,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.PEER_PORT" server.port
"status.code" "UNKNOWN"
"grpc.status.code" "UNKNOWN"
"$InstrumentationTags.GRPC_STATUS_CODE" 2
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
"status.description" { it == null || String}
Expand All @@ -448,6 +454,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "${status.code.name()}"
"grpc.status.code" "${status.code.name()}"
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
"status.description" { it == null || String}
errorTags error.class, error.message
if ({ isDataStreamsEnabled() }) {
Expand Down Expand Up @@ -554,6 +561,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
if ({ isDataStreamsEnabled() }) {
"$DDTags.PATHWAY_HASH" { String }
}
Expand Down Expand Up @@ -621,6 +629,7 @@ abstract class GrpcTest extends VersionedNamingTestBase {
"$Tags.RPC_SERVICE" "example.Greeter"
"status.code" "OK"
"grpc.status.code" "OK"
"$InstrumentationTags.GRPC_STATUS_CODE" 0
"request.type" "example.Helloworld\$Request"
"response.type" "example.Helloworld\$Response"
if ({ isDataStreamsEnabled() }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.common.metrics;

import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V06_METRICS_ENDPOINT;
import static datadog.trace.api.DDSpanTypes.RPC;
import static datadog.trace.api.DDTags.BASE_SERVICE;
import static datadog.trace.api.Functions.UTF8_ENCODE;
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_ENDPOINT;
Expand Down Expand Up @@ -29,6 +30,7 @@
import datadog.trace.api.WellKnownTags;
import datadog.trace.api.cache.DDCache;
import datadog.trace.api.cache.DDCaches;
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import datadog.trace.common.metrics.SignalItem.ReportSignal;
import datadog.trace.common.writer.ddagent.DDAgentApi;
Expand Down Expand Up @@ -326,21 +328,28 @@ private boolean publish(CoreSpan<?> span, boolean isTopLevel, CharSequence spanK
httpEndpoint = httpEndpointObj != null ? httpEndpointObj.toString() : null;
}

CharSequence spanType = span.getType();
String grpcStatusCode = null;
if (spanType != null && RPC.contentEquals(spanType)) {
Object grpcStatusObj = span.unsafeGetTag(InstrumentationTags.GRPC_STATUS_CODE);
grpcStatusCode = grpcStatusObj != null ? grpcStatusObj.toString() : null;
}
MetricKey newKey =
new MetricKey(
span.getResourceName(),
SERVICE_NAMES.computeIfAbsent(span.getServiceName(), UTF8_ENCODE),
span.getOperationName(),
span.getServiceNameSource(),
span.getType(),
spanType,
span.getHttpStatusCode(),
isSynthetic(span),
span.getParentId() == 0,
SPAN_KINDS.computeIfAbsent(
spanKind, UTF8BytesString::create), // save repeated utf8 conversions
getPeerTags(span, spanKind.toString()),
httpMethod,
httpEndpoint);
httpEndpoint,
grpcStatusCode);
MetricKey key = keys.putIfAbsent(newKey, newKey);
if (null == key) {
key = newKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public final class MetricKey {
static final DDCache<String, UTF8BytesString> HTTP_METHOD_CACHE = DDCaches.newFixedSizeCache(8);
static final DDCache<String, UTF8BytesString> HTTP_ENDPOINT_CACHE =
DDCaches.newFixedSizeCache(32);
static final DDCache<String, UTF8BytesString> GRPC_STATUS_CODE_CACHE =
DDCaches.newFixedSizeCache(32);

private final UTF8BytesString resource;
private final UTF8BytesString service;
Expand All @@ -36,6 +38,7 @@ public final class MetricKey {
private final List<UTF8BytesString> peerTags;
private final UTF8BytesString httpMethod;
private final UTF8BytesString httpEndpoint;
private final UTF8BytesString grpcStatusCode;

public MetricKey(
CharSequence resource,
Expand All @@ -49,7 +52,8 @@ public MetricKey(
CharSequence spanKind,
List<UTF8BytesString> peerTags,
CharSequence httpMethod,
CharSequence httpEndpoint) {
CharSequence httpEndpoint,
CharSequence grpcStatusCode) {
this.resource = null == resource ? EMPTY : utf8(RESOURCE_CACHE, resource);
this.service = null == service ? EMPTY : utf8(SERVICE_CACHE, service);
this.serviceSource = null == serviceSource ? null : utf8(SERVICE_SOURCE_CACHE, serviceSource);
Expand All @@ -62,6 +66,8 @@ public MetricKey(
this.peerTags = peerTags == null ? Collections.emptyList() : peerTags;
this.httpMethod = httpMethod == null ? null : utf8(HTTP_METHOD_CACHE, httpMethod);
this.httpEndpoint = httpEndpoint == null ? null : utf8(HTTP_ENDPOINT_CACHE, httpEndpoint);
this.grpcStatusCode =
grpcStatusCode == null ? null : utf8(GRPC_STATUS_CODE_CACHE, grpcStatusCode);

int tmpHash = 0;
tmpHash = HashingUtils.addToHash(tmpHash, this.isTraceRoot);
Expand All @@ -76,6 +82,7 @@ public MetricKey(
tmpHash = HashingUtils.addToHash(tmpHash, this.serviceSource);
tmpHash = HashingUtils.addToHash(tmpHash, this.httpEndpoint);
tmpHash = HashingUtils.addToHash(tmpHash, this.httpMethod);
tmpHash = HashingUtils.addToHash(tmpHash, this.grpcStatusCode);
this.hash = tmpHash;
}

Expand Down Expand Up @@ -135,6 +142,10 @@ public UTF8BytesString getHttpEndpoint() {
return httpEndpoint;
}

public UTF8BytesString getGrpcStatusCode() {
return grpcStatusCode;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -154,7 +165,8 @@ public boolean equals(Object o) {
&& peerTags.equals(metricKey.peerTags)
&& Objects.equals(serviceSource, metricKey.serviceSource)
&& Objects.equals(httpMethod, metricKey.httpMethod)
&& Objects.equals(httpEndpoint, metricKey.httpEndpoint);
&& Objects.equals(httpEndpoint, metricKey.httpEndpoint)
&& Objects.equals(grpcStatusCode, metricKey.grpcStatusCode);
}
return false;
}
Expand Down
Loading