Skip to content

Commit

Permalink
customize aws lambda instrumentation to span kind always be SERVER (#286
Browse files Browse the repository at this point in the history
)

*Issue #, if available:*

In OpenTelemetry Python contrib, datadog set the Lambda handler span
kind to be CONSUMER if the Lambda invocation is triggered by
SNS/SQS/DDB, but actually that logic should be applied to Lambda Service
span. The Lambda handler span should be always SERVER since it is
triggered by Lambda Service.

*Description of changes:*
Update the span kind of Lambda handler span to be SERVER from ADOT SDK
repo.

After this change, the Lambda handler segment name looks normal
```
{
            "Id": "5da4657e70beac54",
            "Document": {
                "id": "5da4657e70beac54",
                "name": "snsSubscriber",
                "start_time": 1730158477.6370573,
                "trace_id": "1-67201f8d-4cf059993c2b913f2127f7da",
                "end_time": 1730158478.2419734,
                "parent_id": "b00ba984da7fd16f",
                "aws": {
                    "span.kind": "LOCAL_ROOT",
                    "log.group.names": "/aws/lambda/snsSubscriber"
                },
                "annotations": {
                    "aws.local.service": "snsSubscriber",
                    "span.name": "lambda_function.lambda_handler",
                    "aws.local.operation": "snsSubscriber/FunctionHandler",
                    "span.kind": "SERVER",
                    "aws.local.environment": "lambda:default"
                },
                "metadata": {
                    "cloud.region": "us-west-1",
                    "service.name": "snsSubscriber",
                    "faas.name": "snsSubscriber",
                    "telemetry.sdk.name": "opentelemetry",
                    "aws.span.kind": "LOCAL_ROOT",
                    "telemetry.sdk.language": "python",
                    "cloud.provider": "aws",
                    "faas.invocation_id": "c8aff945-7d0a-472a-9785-97763944efbf",
                    "cloud.account.id": "816069141447",
                    "cloud.resource_id": "arn:aws:lambda:us-west-1:816069141447:function:snsSubscriber",
                    "faas.instance": "2024/10/28/[$LATEST]88c0a736ba8d42bab162aa3a25180f73",
                    "aws.log.group.names": "/aws/lambda/snsSubscriber",
                    "telemetry.sdk.version": "1.27.0",
                    "faas.version": "$LATEST",
                    "PlatformType": "AWS::Lambda",
                    "telemetry.auto.version": "0.6.0.dev0-aws"
                },
```

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
  • Loading branch information
wangzlei authored Oct 29, 2024
1 parent 7bf7202 commit 13fb4dc
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lambda-layer/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ WORKDIR /workspace

RUN sed -i "/opentelemetry-exporter-otlp-proto-grpc/d" ./aws-opentelemetry-distro/pyproject.toml

RUN sed -i "/opentelemetry-instrumentation-aws-lambda/d" ./aws-opentelemetry-distro/pyproject.toml

RUN sed -i "/opentelemetry-instrumentation-system-metrics/d" ./aws-opentelemetry-distro/pyproject.toml

RUN mkdir -p /build && \
python3 -m pip install aws-opentelemetry-distro/ -t /build/python && \
cp -r opentelemetry /build/python && \
mv otel_wrapper.py /build/python && \
mv otel-instrument /build && \
python3 -m compileall /build/python && \
Expand Down
Loading

0 comments on commit 13fb4dc

Please sign in to comment.