Problem: CloudWatch metrics or invocations not appearing
After instrumenting your AWS Lambda function with OpenTelemetry and invoking it, the CloudWatch metrics section or Invocations tab doesn't appear in the New Relic UI.
Solution
New Relic requires the following OpenTelemetry resource attributes to correctly identify and display your Lambda function in the UI:
| Attribute | Description | Example value |
|---|---|---|
faas.name | The name of the Lambda function | my-lambda-function |
faas.id | The full ARN of the Lambda function | arn:aws:lambda:us-east-1:123456789012:function:my-lambda-function |
If these attributes are missing, set them using the OTEL_RESOURCE_ATTRIBUTES environment variable.
SAM template:
yourFunctionHere: Type: AWS::Serverless::Function Properties: # ... Environment: Variables: OTEL_RESOURCE_ATTRIBUTES: "faas.name=my-lambda-function,faas.id=arn:aws:lambda:us-east-1:123456789012:function:my-lambda-function"Important
Replace my-lambda-function and the ARN with your actual function name and ARN. The ARN must match the value shown in the AWS Lambda console exactly.
AWS Console:
- Open your function in the Lambda Console.
- Choose Configuration, then Environment variables.
- Choose Edit, then Add environment variable.
- Set Key to
OTEL_RESOURCE_ATTRIBUTESand Value tofaas.name=my-lambda-function,faas.id=arn:aws:lambda:us-east-1:123456789012:function:my-lambda-function. - Choose Save.
If you already have other resource attributes set, append the new values as comma-separated key-value pairs:
OTEL_RESOURCE_ATTRIBUTES=service.name=my-service,faas.name=my-lambda-function,faas.id=arn:aws:lambda:us-east-1:123456789012:function:my-lambda-functionProblem: Request ID missing on traces
Your Lambda function traces appear in New Relic, but the AWS request ID isn't visible on the root span, making it difficult to correlate traces with CloudWatch Logs entries.
Solution
Set the faas.execution attribute on the root span inside your handler. The OpenTelemetry semantic conventions define this attribute as the cloud provider's request or invocation ID.
Python:
from opentelemetry import trace
def handler(event, context): span = trace.get_current_span() span.set_attribute("faas.execution", context.aws_request_id)
# Your handler logic here return {"statusCode": 200, "body": "OK"}Node.js:
const { trace } = require('@opentelemetry/api');
exports.handler = async (event, context) => { const span = trace.getActiveSpan(); if (span) { span.setAttribute('faas.execution', context.awsRequestId); }
// Your handler logic here return { statusCode: 200, body: 'OK' };};Java:
import io.opentelemetry.api.trace.Span;
public class Handler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) { Span span = Span.current(); span.setAttribute("faas.execution", context.getAwsRequestId());
// Your handler logic here return new APIGatewayProxyResponseEvent().withStatusCode(200); }}Conseil
New Relic surfaces faas.execution as Request ID in the trace details panel, making it easy to find the corresponding CloudWatch Logs entry for any invocation.
More information
For more information, see the following: