Skip to content

Commit

Permalink
Set function name as service.name in java/nodejs when needed and load… (
Browse files Browse the repository at this point in the history
open-telemetry#70)

* Set function name as service.name in java/nodejs when needed and load env/process detector in nodejs.

* Remove debugging
  • Loading branch information
Anuraag Agrawal authored Apr 23, 2021
1 parent 50e70b6 commit 8a18993
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions java/layer-javaagent/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

export JAVA_TOOL_OPTIONS="-javaagent:/opt/opentelemetry-javaagent.jar ${JAVA_TOOL_OPTIONS}"

if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi

exec "$@"
4 changes: 4 additions & 0 deletions java/layer-wrapper/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestWrapper"

if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi

exec "$@"
4 changes: 4 additions & 0 deletions java/layer-wrapper/scripts/otel-proxy-handler
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestApiGatewayWrapper"

if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi

exec "$@"
4 changes: 4 additions & 0 deletions java/layer-wrapper/scripts/otel-stream-handler
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamWrapper"

if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi

exec "$@"
4 changes: 4 additions & 0 deletions nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"

if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi

exec "$@"
9 changes: 8 additions & 1 deletion nodejs/packages/layer/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lam
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector-proto';
import { awsLambdaDetector } from '@opentelemetry/resource-detector-aws';
import {
detectResources,
envDetector,
processDetector,
} from '@opentelemetry/resources';
import { AwsInstrumentation } from 'opentelemetry-instrumentation-aws-sdk';

declare global {
Expand All @@ -31,7 +36,9 @@ registerInstrumentations({
});

async function initializeProvider() {
const resource = await awsLambdaDetector.detect();
const resource = await detectResources({
detectors: [awsLambdaDetector, envDetector, processDetector],
});

let config: NodeTracerConfig = {
resource,
Expand Down

0 comments on commit 8a18993

Please sign in to comment.