Suppress nested http client spans in aws2 instrumentation (#9634)

This commit is contained in:
Lauri Tulmin 2023-10-10 10:21:30 +03:00 committed by GitHub
parent aeb332f96b
commit 6f0fd8e631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 4 deletions

View File

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

View File

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

View File

@ -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 =