Skip to content

Conversation

@syed-ahsan-ishtiaque
Copy link

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

Summary

When OTEL_METRICS_ADD_APPLICATION_SIGNALS_DIMENSIONS is set to true, EMF metrics will include Service and Environment as dimensions:

  • Service: Extracted from service.name resource attribute, falls back to "UnknownService"
  • Environment: Extracted from deployment.environment.name or deployment.environment resource attribute, falls back to platform-specific default
  • Dimensions are not added if user already set them (case-insensitive check)

Platform-Specific Defaults

Cloud Platform Default Environment
AWS Lambda lambda:default
AWS EC2 ec2:default
AWS ECS ecs:default
AWS EKS eks:default
Unknown/Other generic:default

For Lambda, the env var defaults to true via the otel-instrument wrapper script.

Changes

  1. src/exporter/aws/metrics/emf-exporter-base.ts

    • Added shouldAddApplicationSignalsDimensions() to check the single env var
    • Added getDefaultEnvironmentForPlatform() for platform-aware defaults
    • Added hasDimensionCaseInsensitive() for case-insensitive dimension checking
    • Added addApplicationSignalsDimensions() to inject Service/Environment dimensions
    • Modified createEmfLog() to call the new method
  2. lambda-layer/packages/layer/scripts/otel-instrument

    • Added default OTEL_METRICS_ADD_APPLICATION_SIGNALS_DIMENSIONS="true" for Lambda
  3. test/exporter/aws/metrics/aws-cloudwatch-emf-exporter.test.ts

    • Added 16 new test cases covering all scenarios including platform-specific defaults

Test plan

  • npm run lint passes (0 errors)
  • npm run compile builds successfully
  • All unit tests pass
  • Integration test on Lambda verified Service/Environment dimensions in CloudWatch metrics

Manual Testing

Lambda Code

import { metrics, trace } from '@opentelemetry/api';
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';

const tracer = trace.getTracer('test-tracer');
const meter = metrics.getMeter('test-meter');
const requestCounter = meter.createCounter('test.requests', {
  unit: '1',
  description: 'Test request counter'
});

const s3Client = new S3Client({});

export const handler = async (event, context) => {
  // Custom metric emission
  requestCounter.add(1, { operation: 'test' });

  // AWS SDK call
  try {
    await s3Client.send(new ListBucketsCommand({}));
  } catch (e) {
    console.log('S3 call error (expected if no permissions):', e.message);
  }

  // Custom span with HTTP call
  const span = tracer.startSpan('my-custom-span');
  span.setAttribute('key1', 'value1');
  try {
    const response = await fetch('https://aws.amazon.com');
    span.setAttribute('http.status_code', response.status);
    console.log('HTTP call to aws.amazon.com status:', response.status);
  } catch (e) {
    console.log('HTTP call error:', e.message);
    span.setAttribute('error', true);
  }
  span.end();

  return {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Metrics and traces emitted',
      functionName: process.env.AWS_LAMBDA_FUNCTION_NAME
    })
  };
};

CW Metrics

image

Application Signals Related Metrics

image

🤖 Generated with Claude Code

@syed-ahsan-ishtiaque syed-ahsan-ishtiaque requested a review from a team as a code owner December 5, 2025 07:06
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-emf-service-environment-dimensions branch from 3e9cd4a to 91155d3 Compare December 5, 2025 07:08
When both OTEL_AWS_APPLICATION_SIGNALS_ENABLED and
OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED are set to true,
EMF metrics will now include Service and Environment as dimensions:

- Service: extracted from service.name resource attribute,
  falls back to "UnknownService"
- Environment: extracted from deployment.environment resource
  attribute, falls back to "lambda:default"
- Dimensions are not added if user already set them (case-insensitive)

For Lambda, both env vars default to true via otel-instrument wrapper.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-emf-service-environment-dimensions branch from 91155d3 to 363f95e Compare December 9, 2025 03:50
Comment on lines +79 to +80
# - Set Application Signals EMF export configuration (adds Service and Environment dimensions)
if [ -z "${OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED}" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the purpose of OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED is to only addApplicationSignalsDimensions to EMF, can we use a different Env Var for this?

syed-ahsan-ishtiaque and others added 2 commits December 18, 2025 18:57
Changes from v1 to v2 implementation:
- Use single env var: OTEL_METRICS_ADD_APPLICATION_SIGNALS_DIMENSIONS
- Add platform-aware defaults: lambda:default, ec2:default, ecs:default, eks:default, generic:default
- Check deployment.environment.name before deployment.environment
- Detect platform via cloud.platform resource attribute

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

Co-Authored-By: Claude <noreply@anthropic.com>
Use push() instead of unshift/splice to add Service and Environment
dimensions without enforcing specific position in the dimensions array.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@syed-ahsan-ishtiaque syed-ahsan-ishtiaque force-pushed the add-emf-service-environment-dimensions branch from c77565d to 53497c6 Compare December 19, 2025 03:29
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