Use X-Ray propagator for aws sdk 1.1 instrumentation (#2117)
* Use X-Ray propagator for aws sdk 1.1 instrumentation * Cleaner * Fix * Copy over doc
This commit is contained in:
parent
782a646d89
commit
6b13bcca63
|
@ -77,7 +77,7 @@ public abstract class HttpClientTracer<REQUEST, CARRIER, RESPONSE> extends BaseT
|
|||
return context;
|
||||
}
|
||||
|
||||
private void inject(Context context, CARRIER carrier) {
|
||||
protected void inject(Context context, CARRIER carrier) {
|
||||
Setter<CARRIER> setter = getSetter();
|
||||
if (setter == null) {
|
||||
throw new IllegalStateException(
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# AWS Java SDK v1 Instrumentation
|
||||
|
||||
Instrumentation for [AWS Java SDK v1](https://github.com/aws/aws-sdk-java).
|
||||
|
||||
## Trace propagation
|
||||
|
||||
The AWS SDK instrumentation currently only supports injecting the trace header into the request
|
||||
using the [AWS Trace Header](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader) format.
|
||||
This format is the only format recognized by AWS managed services, and populating will allow
|
||||
propagating the trace through them. If this does not fulfill your use case, perhaps because you are
|
||||
using the same SDK with a different non-AWS managed service, let us know so we can provide
|
||||
configuration for this behavior.
|
|
@ -45,6 +45,8 @@ configurations {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly deps.opentelemetryTraceProps
|
||||
|
||||
library group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.0'
|
||||
|
||||
// Include httpclient instrumentation for testing because it is a dependency for aws-sdk.
|
||||
|
@ -56,6 +58,9 @@ dependencies {
|
|||
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.106'
|
||||
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.106'
|
||||
|
||||
// Make sure doesn't add HTTP headers
|
||||
testInstrumentation project(':instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent')
|
||||
|
||||
// needed for kinesis:
|
||||
testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-cbor', version: versions.jackson
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.amazonaws.Response;
|
|||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||
import io.opentelemetry.extension.trace.propagation.AwsXrayPropagator;
|
||||
import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -30,6 +31,11 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
|
|||
|
||||
public AwsSdkClientTracer() {}
|
||||
|
||||
@Override
|
||||
protected void inject(Context context, Request<?> request) {
|
||||
AwsXrayPropagator.getInstance().inject(context, request, AwsSdkInjectAdapter.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String spanNameForRequest(Request<?> request) {
|
||||
if (request == null) {
|
||||
|
@ -112,7 +118,8 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
|
|||
|
||||
@Override
|
||||
protected TextMapPropagator.Setter<Request<?>> getSetter() {
|
||||
return AwsSdkInjectAdapter.INSTANCE;
|
||||
// We override injection and don't want to have the base class do it accidentally.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,11 @@ public class AwsSdkInstrumentationModule extends InstrumentationModule {
|
|||
super("aws-sdk", "aws-sdk-1.11");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] additionalHelperClassNames() {
|
||||
return new String[] {"io.opentelemetry.extension.trace.propagation.AwsXrayPropagator"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return asList(
|
||||
|
|
|
@ -159,7 +159,8 @@ class Aws1ClientTest extends AgentTestRunner {
|
|||
}
|
||||
}
|
||||
}
|
||||
server.lastRequest.headers.get("traceparent") != null
|
||||
server.lastRequest.headers.get("X-Amzn-Trace-Id") != null
|
||||
server.lastRequest.headers.get("traceparent") == null
|
||||
|
||||
where:
|
||||
service | operation | method | path | handlerCount | client | call | additionalAttributes | body
|
||||
|
|
|
@ -122,7 +122,8 @@ class Aws0ClientTest extends AgentTestRunner {
|
|||
}
|
||||
}
|
||||
}
|
||||
server.lastRequest.headers.get("traceparent") != null
|
||||
server.lastRequest.headers.get("X-Amzn-Trace-Id") != null
|
||||
server.lastRequest.headers.get("traceparent") == null
|
||||
|
||||
where:
|
||||
service | operation | method | path | handlerCount | client | additionalAttributes | call | body
|
||||
|
|
Loading…
Reference in New Issue