Skip to content

fix(serverless): add base_service tag for serverless [backport #17238 to 4.6]#17437

Closed
zarirhamza wants to merge 1 commit into4.6from
backport-17238-to-4.6
Closed

fix(serverless): add base_service tag for serverless [backport #17238 to 4.6]#17437
zarirhamza wants to merge 1 commit into4.6from
backport-17238-to-4.6

Conversation

@zarirhamza
Copy link
Copy Markdown
Contributor

Backport of #17238 to 4.6.

(cherry picked from commit 93778cc)

Description

Fixes _dd.base_service handling for AWS Lambda environments in the Python tracer, enabling service remapping rules to work on Lambda spans and ensuring trace stats contain a meaningful base_service.

Changes

ddtrace/internal/settings/_config.py — When DD_SERVICE is not configured and the tracer is running in AWS Lambda, config.service is now automatically set from AWS_LAMBDA_FUNCTION_NAME. This mirrors existing GCP (K_SERVICE) and Azure (WEBSITE_SITE_NAME) auto-detection behavior.

ddtrace/internal/schema/processor.py — Removes the Lambda-specific early exit from BaseServiceProcessor. Previously, the processor skipped all Lambda spans to avoid unhelpful base_service values from the runtime. Now that the service is correctly resolved from the function name, the processor runs normally and _dd.base_service is properly attached to spans.

Testing

Existing serverless system tests pass (ALB, API Gateway HTTP/REST, Function URL). Includes new unit tests for Lambda service name auto-detection and base_service processor behavior.

Risks

Low. The change only affects Lambda environments where DD_SERVICE is not explicitly set. The resolved service name (AWS_LAMBDA_FUNCTION_NAME) matches what the extension already uses for extension-based languages, ensuring consistency across runtimes.

## Overview

Fixes `_dd.base_service` handling for AWS Lambda environments in the Python tracer, enabling service remapping rules to work on Lambda spans and ensuring trace stats contain a meaningful `base_service`.

### Changes

**`ddtrace/internal/settings/_config.py`** — When `DD_SERVICE` is not configured and the tracer is running in AWS Lambda, `config.service` is now automatically set from `AWS_LAMBDA_FUNCTION_NAME`. This mirrors existing GCP (`K_SERVICE`) and Azure (`WEBSITE_SITE_NAME`) auto-detection behavior.

**`ddtrace/internal/schema/processor.py`** — Removes the Lambda-specific early exit from `BaseServiceProcessor`. Previously, the processor skipped all Lambda spans to avoid unhelpful `base_service` values from the runtime. Now that the service is correctly resolved from the function name, the processor runs normally and `_dd.base_service` is properly attached to spans.

## Testing

Existing serverless system tests pass (ALB, API Gateway HTTP/REST, Function URL).

## Risks

Low. The change only affects Lambda environments where `DD_SERVICE` is not explicitly set. The resolved service name (`AWS_LAMBDA_FUNCTION_NAME`) matches what the extension already uses for extension-based languages, ensuring consistency across runtimes.

Co-authored-by: zarir.hamza <zarir.hamza@datadoghq.com>
@zarirhamza zarirhamza requested review from a team as code owners April 9, 2026 20:40
@cit-pr-commenter-54b7da
Copy link
Copy Markdown

Codeowners resolved as

ddtrace/internal/schema/processor.py                                    @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/internal/settings/_config.py                                    @DataDog/python-guild @DataDog/apm-sdk-capabilities-python
releasenotes/notes/serverless-base-service-lambda-b3c9f1e2d4a58701.yaml  @DataDog/apm-python
tests/internal/service_name/test_processor.py                           @DataDog/apm-core-python
tests/tracer/test_tracer.py                                             @DataDog/apm-sdk-capabilities-python @DataDog/apm-core-python

@zarirhamza zarirhamza enabled auto-merge (squash) April 9, 2026 21:05
@zarirhamza zarirhamza disabled auto-merge April 9, 2026 21:07
@zarirhamza zarirhamza closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants