Skip to content

Commit

Permalink
Suppress nested http client spans in aws2 instrumentation (#9634)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Oct 10, 2023
1 parent aeb332f commit 6f0fd8e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ dependencies {

testImplementation(project(":instrumentation:aws-sdk:aws-sdk-2.2:testing"))
// Make sure these don't add HTTP headers
testImplementation(project(":instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent"))
testImplementation(project(":instrumentation:netty:netty-4.1:javaagent"))
testInstrumentation(project(":instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent"))
testInstrumentation(project(":instrumentation:apache-httpclient:apache-httpclient-5.0:javaagent"))
testInstrumentation(project(":instrumentation:netty:netty-4.1:javaagent"))

testLibrary("software.amazon.awssdk:dynamodb:2.2.0")
testLibrary("software.amazon.awssdk:ec2:2.2.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
import javax.annotation.Nullable;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.http.SdkHttpResponse;

/**
* An attribute extractor that reports implementing HTTP client semantic conventions. Adding this
* extractor suppresses nested HTTP client instrumentations similarly to how using {@link
* HttpClientAttributesExtractor} would.
*/
class AwsSdkHttpClientSuppressionAttributesExtractor
implements AttributesExtractor<ExecutionAttributes, SdkHttpResponse>, SpanKeyProvider {

@Override
public void onStart(
AttributesBuilder attributes,
Context parentContext,
ExecutionAttributes executionAttributes) {}

@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
ExecutionAttributes executionAttributes,
@Nullable SdkHttpResponse sdkHttpResponse,
@Nullable Throwable error) {}

@Nullable
@Override
public SpanKey internalGetSpanKey() {
return SpanKey.HTTP_CLIENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ final class AwsSdkInstrumenterFactory {
static final AttributesExtractor<ExecutionAttributes, SdkHttpResponse> httpAttributesExtractor =
HttpClientAttributesExtractor.create(httpAttributesGetter);

private static final AttributesExtractor<ExecutionAttributes, SdkHttpResponse>
httpClientSuppressionAttributesExtractor =
new AwsSdkHttpClientSuppressionAttributesExtractor();

private static final AwsSdkSpanKindExtractor spanKindExtractor = new AwsSdkSpanKindExtractor();

private static final List<AttributesExtractor<ExecutionAttributes, SdkHttpResponse>>
defaultAttributesExtractors = Arrays.asList(rpcAttributesExtractor);
defaultAttributesExtractors =
Arrays.asList(rpcAttributesExtractor, httpClientSuppressionAttributesExtractor);

private static final List<AttributesExtractor<ExecutionAttributes, SdkHttpResponse>>
extendedAttributesExtractors =
Arrays.asList(rpcAttributesExtractor, experimentalAttributesExtractor);
Arrays.asList(
rpcAttributesExtractor,
experimentalAttributesExtractor,
httpClientSuppressionAttributesExtractor);

private static final List<AttributesExtractor<ExecutionAttributes, SdkHttpResponse>>
defaultConsumerAttributesExtractors =
Expand Down

0 comments on commit 6f0fd8e

Please sign in to comment.