Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress nested http client spans in aws2 instrumentation #9634

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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 @@ -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