Skip to content

Conversation

@syed-ahsan-ishtiaque
Copy link
Contributor

@syed-ahsan-ishtiaque syed-ahsan-ishtiaque commented Dec 4, 2025

Summary

When both OTEL_AWS_APPLICATION_SIGNALS_ENABLED and
OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED are true, inject
"Service" and "Environment" dimensions into EMF metrics.

  • Service: extracted from resource via get_service_attribute(), falls
    back to "UnknownService"
  • Environment: extracted from deployment.environment resource attribute,
    falls back to "lambda:default"
  • Case-insensitive check prevents overwriting user-set dimensions
  • Lambda wrapper sets OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED=true
    by default

Test plan

  • Unit tests added for Lambda dimension injection in test_base_emf_exporter.py
  • Unit tests added for is_lambda parameter in test_console_emf_exporter.py
  • Existing configurator tests updated in test_aws_opentelementry_configurator.py
  • Integration tested on Lambda
  • Verified EMF output contains Service and Environment dimensions
  • Verified CloudWatch metrics have correct dimensions

Testing

Lambda Code

import json
import os

import boto3
import requests
from opentelemetry import metrics, trace

# Get tracer and meter
tracer = trace.get_tracer(__name__)
meter = metrics.get_meter(__name__)

# Create a counter for custom metrics
request_counter = meter.create_counter(
    "test.requests",
    unit="1",
    description="Test request counter"
)

# Initialize S3 client (outside handler for connection reuse)
s3_client = boto3.client("s3")


def lambda_handler(event, context):
    # 1. Custom span with HTTP call - generates Application Signals service metrics
    with tracer.start_as_current_span("my-custom-span") as span:
        span.set_attribute("key1", "value1")
        span.add_event("custom-event", {"detail": "something happened"})
        requests.get("https://aws.amazon.com/")

    # 2. AWS SDK call - generates Application Signals dependency metrics
    s3_client.list_buckets()

    # 3. Custom metric emission - will be converted to EMF
    request_counter.add(1, {"operation": "test"})

    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "Metrics and traces emitted",
            "function_name": os.environ.get("AWS_LAMBDA_FUNCTION_NAME"),
            "trace_id": os.environ.get("_X_AMZN_TRACE_ID")
        })
    }

CW Metrics

image

Application Signals Related Metrics

image

🤖 Generated with Claude Code

@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-lambda-emf-service-environment-dimensions branch from 607d03e to 3cdbfa7 Compare December 4, 2025 19:02
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque changed the title Add Service and Environment dimensions to EMF metrics for Lambda Add Service and Environment dimensions to EMF metrics when Application Signals is enabled Dec 4, 2025
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-lambda-emf-service-environment-dimensions branch 4 times, most recently from eefdb6c to add1a3c Compare December 5, 2025 05:54
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-lambda-emf-service-environment-dimensions branch from add1a3c to 1609459 Compare December 5, 2025 18:55
…n Signals is enabled

When both OTEL_AWS_APPLICATION_SIGNALS_ENABLED and
OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED are true, inject
"Service" and "Environment" dimensions into EMF metrics.

- Service: extracted from resource via get_service_attribute(), falls
  back to "UnknownService"
- Environment: extracted from deployment.environment resource attribute,
  falls back to "lambda:default"
- Case-insensitive check prevents overwriting user-set dimensions
- Lambda wrapper sets OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED=true
  by default

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-lambda-emf-service-environment-dimensions branch from 1609459 to 02d5cae Compare December 5, 2025 19:00
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque merged commit 985be39 into main Dec 5, 2025
25 of 27 checks passed
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque deleted the add-lambda-emf-service-environment-dimensions branch December 5, 2025 21:38
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.

2 participants