Skip to content
Closed
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 @@ -5,23 +5,29 @@

package io.opentelemetry.javaagent.instrumentation.awslambdacore.v1_0;

import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.AwsLambdaFunctionInstrumenter;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.AwsLambdaFunctionInstrumenterFactory;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.WrapperConfiguration;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import java.time.Duration;

public final class AwsLambdaSingletons {

private static final AwsLambdaFunctionInstrumenter FUNCTION_INSTRUMENTER =
AwsLambdaFunctionInstrumenterFactory.createInstrumenter(GlobalOpenTelemetry.get());
private static final Duration FLUSH_TIMEOUT =
Duration.ofMillis(
AgentInstrumentationConfig.get()
.getLong(
"otel.instrumentation.aws-lambda.flush-timeout",
WrapperConfiguration.OTEL_LAMBDA_FLUSH_TIMEOUT_DEFAULT.toMillis()));
private static final AwsLambdaFunctionInstrumenter FUNCTION_INSTRUMENTER;
private static final Duration FLUSH_TIMEOUT;

static {
Configuration config = new Configuration(GlobalOpenTelemetry.get());

FLUSH_TIMEOUT = Duration.ofMillis(config.flushTimeout);
FUNCTION_INSTRUMENTER =
AwsLambdaFunctionInstrumenterFactory.createInstrumenter(GlobalOpenTelemetry.get());
}

public static AwsLambdaFunctionInstrumenter functionInstrumenter() {
return FUNCTION_INSTRUMENTER;
Expand All @@ -31,5 +37,31 @@ public static Duration flushTimeout() {
return FLUSH_TIMEOUT;
}

// instrumentation/development:
// java:
// aws_lambda:
// flush_timeout: 10000
private static final class Configuration {

private final long flushTimeout;

Configuration(OpenTelemetry openTelemetry) {
DeclarativeConfigProperties javaConfig = empty();
if (openTelemetry instanceof ExtendedOpenTelemetry) {
ExtendedOpenTelemetry extendedOpenTelemetry = (ExtendedOpenTelemetry) openTelemetry;
DeclarativeConfigProperties instrumentationConfig =
extendedOpenTelemetry.getConfigProvider().getInstrumentationConfig();
if (instrumentationConfig != null) {
javaConfig = instrumentationConfig.getStructured("java", empty());
}
}
DeclarativeConfigProperties awsLambdaConfig = javaConfig.getStructured("aws_lambda", empty());

this.flushTimeout =
awsLambdaConfig.getLong(
"flush_timeout", WrapperConfiguration.OTEL_LAMBDA_FLUSH_TIMEOUT_DEFAULT.toMillis());
}
}

private AwsLambdaSingletons() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@

package io.opentelemetry.javaagent.instrumentation.awslambdaevents.v2_2;

import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;

import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.AwsLambdaFunctionInstrumenter;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.WrapperConfiguration;
import io.opentelemetry.instrumentation.awslambdaevents.common.v2_2.internal.AwsLambdaEventsInstrumenterFactory;
import io.opentelemetry.instrumentation.awslambdaevents.common.v2_2.internal.AwsLambdaSqsInstrumenterFactory;
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import java.time.Duration;

public final class AwsLambdaSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aws-lambda-events-2.2";
private static final AwsLambdaFunctionInstrumenter FUNCTION_INSTRUMENTER =
AwsLambdaEventsInstrumenterFactory.createInstrumenter(
GlobalOpenTelemetry.get(),
INSTRUMENTATION_NAME,
AgentCommonConfig.get().getKnownHttpRequestMethods());
private static final Instrumenter<SQSEvent, Void> MESSAGE_TRACER =
AwsLambdaSqsInstrumenterFactory.forEvent(GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME);
private static final Duration FLUSH_TIMEOUT =
Duration.ofMillis(
AgentInstrumentationConfig.get()
.getLong(
"otel.instrumentation.aws-lambda.flush-timeout",
WrapperConfiguration.OTEL_LAMBDA_FLUSH_TIMEOUT_DEFAULT.toMillis()));

private static final AwsLambdaFunctionInstrumenter FUNCTION_INSTRUMENTER;
private static final Instrumenter<SQSEvent, Void> MESSAGE_TRACER;
private static final Duration FLUSH_TIMEOUT;

static {
Configuration config = new Configuration(GlobalOpenTelemetry.get());

FUNCTION_INSTRUMENTER =
AwsLambdaEventsInstrumenterFactory.createInstrumenter(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME);
MESSAGE_TRACER =
AwsLambdaSqsInstrumenterFactory.forEvent(GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME);
FLUSH_TIMEOUT = Duration.ofMillis(config.flushTimeout);
}

public static AwsLambdaFunctionInstrumenter functionInstrumenter() {
return FUNCTION_INSTRUMENTER;
Expand All @@ -44,5 +49,44 @@ public static Duration flushTimeout() {
return FLUSH_TIMEOUT;
}

// instrumentation/development:
// java:
// aws_lambda:
// flush_timeout: 10000
// http:
// known_methods:
// - CONNECT
// - DELETE
// - GET
// - HEAD
// - OPTIONS
// - PATCH
// - POST
// - PUT
// - TRACE
private static final class Configuration {

private final long flushTimeout;

Configuration(OpenTelemetry openTelemetry) {
DeclarativeConfigProperties javaConfig = empty();
if (openTelemetry instanceof ExtendedOpenTelemetry) {
ExtendedOpenTelemetry extendedOpenTelemetry = (ExtendedOpenTelemetry) openTelemetry;
DeclarativeConfigProperties instrumentationConfig =
extendedOpenTelemetry.getConfigProvider().getInstrumentationConfig();
if (instrumentationConfig != null) {
javaConfig = instrumentationConfig.getStructured("java", empty());
}
}

this.flushTimeout =
javaConfig
.getStructured("aws_lambda", empty())
.getLong(
"flush_timeout",
WrapperConfiguration.OTEL_LAMBDA_FLUSH_TIMEOUT_DEFAULT.toMillis());
}
}

private AwsLambdaSingletons() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.TracingRequestHandler;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.WrappedLambda;
Expand Down Expand Up @@ -49,7 +48,7 @@ protected TracingRequestWrapperBase(BiFunction<I, Class<?>, Object> parameterMap
openTelemetrySdk,
WrapperConfiguration.flushTimeout(),
AwsLambdaEventsInstrumenterFactory.createInstrumenter(
openTelemetrySdk, INSTRUMENTATION_NAME, HttpConstants.KNOWN_METHODS));
openTelemetrySdk, INSTRUMENTATION_NAME));
this.wrappedLambda = wrappedLambda;
this.targetMethod = wrappedLambda.getRequestTargetMethod();
this.parameterMapper = parameterMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.TracingRequestHandler;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.WrappedLambda;
Expand Down Expand Up @@ -49,7 +48,7 @@ protected TracingRequestWrapperBase(BiFunction<I, Class<?>, Object> parameterMap
openTelemetrySdk,
WrapperConfiguration.flushTimeout(),
AwsLambdaEventsInstrumenterFactory.createInstrumenter(
openTelemetrySdk, INSTRUMENTATION_NAME, HttpConstants.KNOWN_METHODS));
openTelemetrySdk, INSTRUMENTATION_NAME));
this.wrappedLambda = wrappedLambda;
this.targetMethod = wrappedLambda.getRequestTargetMethod();
this.parameterMapper = parameterMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@

package io.opentelemetry.instrumentation.awslambdaevents.common.v2_2.internal;

import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;

import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.AwsLambdaRequest;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.AwsLambdaFunctionAttributesExtractor;
import io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.AwsLambdaFunctionInstrumenter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
Expand All @@ -21,13 +28,14 @@
public final class AwsLambdaEventsInstrumenterFactory {

public static AwsLambdaFunctionInstrumenter createInstrumenter(
OpenTelemetry openTelemetry, String instrumentationName, Set<String> knownMethods) {
OpenTelemetry openTelemetry, String instrumentationName) {
Configuration config = new Configuration(openTelemetry);
return new AwsLambdaFunctionInstrumenter(
openTelemetry,
Instrumenter.builder(
openTelemetry, instrumentationName, AwsLambdaEventsInstrumenterFactory::spanName)
.addAttributesExtractor(new AwsLambdaFunctionAttributesExtractor())
.addAttributesExtractor(new ApiGatewayProxyAttributesExtractor(knownMethods))
.addAttributesExtractor(new ApiGatewayProxyAttributesExtractor(config.knownHttpMethods))
.buildInstrumenter(SpanKindExtractor.alwaysServer()));
}

Expand All @@ -43,5 +51,41 @@ private static String spanName(AwsLambdaRequest input) {
return input.getAwsContext().getFunctionName();
}

// instrumentation/development:
// java:
// http:
// known_methods:
// - CONNECT
// - DELETE
// - GET
// - HEAD
// - OPTIONS
// - PATCH
// - POST
// - PUT
// - TRACE
private static final class Configuration {

private final Set<String> knownHttpMethods;

Configuration(OpenTelemetry openTelemetry) {
DeclarativeConfigProperties javaConfig = empty();
if (openTelemetry instanceof ExtendedOpenTelemetry) {
ExtendedOpenTelemetry extendedOpenTelemetry = (ExtendedOpenTelemetry) openTelemetry;
DeclarativeConfigProperties instrumentationConfig =
extendedOpenTelemetry.getConfigProvider().getInstrumentationConfig();
if (instrumentationConfig != null) {
javaConfig = instrumentationConfig.getStructured("java", empty());
}
}
DeclarativeConfigProperties httpConfig = javaConfig.getStructured("http", empty());

this.knownHttpMethods =
new HashSet<>(
httpConfig.getScalarList(
"known_methods", String.class, new ArrayList<>(HttpConstants.KNOWN_METHODS)));
}
}

private AwsLambdaEventsInstrumenterFactory() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@

package io.opentelemetry.javaagent.instrumentation.awssdk.v1_11;

import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;

import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.Request;
import com.amazonaws.Response;
import com.amazonaws.handlers.HandlerContextKey;
import com.amazonaws.handlers.RequestHandler2;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.awssdk.v1_11.AwsSdkTelemetry;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import io.opentelemetry.javaagent.bootstrap.internal.ExperimentalConfig;
import java.util.Collections;
import java.util.List;

/**
* A {@link RequestHandler2} for use in the agent. Unlike library instrumentation, the agent will
Expand All @@ -33,16 +38,19 @@ public class TracingRequestHandler extends RequestHandler2 {
public static final HandlerContextKey<Scope> SCOPE =
new HandlerContextKey<>(Scope.class.getName());

public static final RequestHandler2 tracingHandler =
AwsSdkTelemetry.builder(GlobalOpenTelemetry.get())
.setCaptureExperimentalSpanAttributes(
AgentInstrumentationConfig.get()
.getBoolean("otel.instrumentation.aws-sdk.experimental-span-attributes", false))
.setMessagingReceiveInstrumentationEnabled(
ExperimentalConfig.get().messagingReceiveInstrumentationEnabled())
.setCapturedHeaders(ExperimentalConfig.get().getMessagingHeaders())
.build()
.newRequestHandler();
public static final RequestHandler2 tracingHandler;

static {
Configuration config = new Configuration(GlobalOpenTelemetry.get());

tracingHandler =
AwsSdkTelemetry.builder(GlobalOpenTelemetry.get())
.setCaptureExperimentalSpanAttributes(config.experimentalSpanAttributes)
.setMessagingReceiveTelemetryEnabled(config.messagingReceiveTelemetryEnabled)
.setCapturedHeaders(config.messagingCapturedHeaders)
.build()
.newRequestHandler();
}

@Override
public void beforeRequest(Request<?> request) {
Expand Down Expand Up @@ -79,4 +87,43 @@ private static void finish(Request<?> request) {
scope.close();
request.addHandlerContext(SCOPE, null);
}

// instrumentation/development:
// java:
// aws_sdk:
// experimental_span_attributes: false
// messaging:
// receive_telemetry/development:
// enabled: false
// capture_headers/development: []
private static final class Configuration {

private final boolean experimentalSpanAttributes;
private final boolean messagingReceiveTelemetryEnabled;
private final List<String> messagingCapturedHeaders;

Configuration(OpenTelemetry openTelemetry) {
DeclarativeConfigProperties javaConfig = empty();
if (openTelemetry instanceof ExtendedOpenTelemetry) {
ExtendedOpenTelemetry extendedOpenTelemetry = (ExtendedOpenTelemetry) openTelemetry;
DeclarativeConfigProperties instrumentationConfig =
extendedOpenTelemetry.getConfigProvider().getInstrumentationConfig();
if (instrumentationConfig != null) {
javaConfig = instrumentationConfig.getStructured("java", empty());
}
}
DeclarativeConfigProperties awsSdkConfig = javaConfig.getStructured("aws_sdk", empty());
DeclarativeConfigProperties messagingConfig = javaConfig.getStructured("messaging", empty());

this.experimentalSpanAttributes =
awsSdkConfig.getBoolean("experimental_span_attributes", false);
this.messagingReceiveTelemetryEnabled =
messagingConfig
.getStructured("receive_telemetry/development", empty())
.getBoolean("enabled", false);
this.messagingCapturedHeaders =
messagingConfig.getScalarList(
"capture_headers/development", String.class, Collections.emptyList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TracingRequestHandler extends RequestHandler2 {
.setCaptureExperimentalSpanAttributes(
ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.aws-sdk.experimental-span-attributes", false))
.setMessagingReceiveInstrumentationEnabled(
.setMessagingReceiveTelemetryEnabled(
ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.messaging.experimental.receive-telemetry.enabled", false))
.setCapturedHeaders(
Expand Down
Loading
Loading