Skip to content

Conversation

@liustve
Copy link
Contributor

@liustve liustve commented May 27, 2025

Issue #, if available:
Supporting ADOT JS auto instrumentation to automatically inject SigV4 authentication headers for outgoing log requests to the allow exporting to the AWS Logs OTLP endpoint. Users will need to configure the following environment variables in order to enable and properly run this exporter:

OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://logs.[AWS-REGION].amazonaws.com/v1/logs; required
OTEL_EXPORTER_OTLP_LOGS_HEADERS=x-aws-log-group=[CW-LOG-GROUP-NAME],x-aws-log-stream=[CW-LOG-STREAM-NAME] required
OTEL_LOGS_EXPORTER=otlp required or do not set env variable
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=http/protobuf required or do not set env variable
OTEL_METRICS_EXPORTER=none

This feature currently supports only 2 logging libraries by auto-instrumentation, Bunyan and Winston:
https://docs.honeycomb.io/send-data/logs/opentelemetry/sdk/javascript/

Description of changes:

  1. Add new AwsAuthenticator class used by both OtlpAwsLogExporter and OtlpAwsSpanExporter which extends the upstream OTLPProtoLogExporter to inject Sigv4 headers directly into the headers.

  2. Modified ADOT JS auto instrumentation to automatically detect if a user is exporting to CW Logs OTLP Logs endpoint by checking if the environment variable OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is configured to match this url pattern: https://logs.[AWS-REGION].amazonaws.com/v1/logs

Testing:

  1. E2E test done in an empty EC2 environment without configuring .aws credentials config file or setting AWS credentials in the environment variable
  2. Manual testing was done by configuring the above environment variables and setting up the sample app locally with ADOT auto instrumentation and verified the logs in CW Logs.
  3. Unit tests were added to verify functionality of OtlpAwsLogsExporter

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Example log in CW Logs:

{
    "resource": {
        "attributes": {
            "service.name": "unknown_service:/home/ec2-user/.local/share/mise/installs/node/22.14.0/bin/node",
            "process.command_args": [
                "/home/ec2-user/.local/share/mise/installs/node/22.14.0/bin/node",
                "--experimental-network-inspection",
                "--require",
                "@aws/aws-distro-opentelemetry-node-autoinstrumentation/register",
                "/home/ec2-user/aws-otel-js-instrumentation/sample-applications/simple-express-server/sample-app-express-server.js"
            ],
            "process.runtime.version": "22.14.0",
            "process.pid": 1599620,
            "process.executable.name": "/home/ec2-user/.local/share/mise/installs/node/22.14.0/bin/node",
            "telemetry.sdk.name": "opentelemetry",
            "process.owner": "ec2-user",
            "telemetry.sdk.language": "nodejs",
            "process.runtime.name": "nodejs",
            "process.executable.path": "/home/ec2-user/.local/share/mise/installs/node/22.14.0/bin/node",
            "host.arch": "amd64",
            "telemetry.sdk.version": "1.30.1",
            "process.command": "/home/ec2-user/aws-otel-js-instrumentation/sample-applications/simple-express-server/sample-app-express-server.js",
            "host.name": "ip-172-31-7-29.us-west-2.compute.internal",
            "process.runtime.description": "Node.js",
            "telemetry.auto.version": "0.6.0-dev0-aws",
            "host.id": "ec2ccd3acc52be039f977d9b1de7c64d"
        }
    },
    "scope": {
        "name": "default"
    },
    "timeUnixNano": 1748220324612000000,
    "observedTimeUnixNano": 1748220324612000000,
    "severityNumber": 9,
    "severityText": "INFO",
    "body": "Received request to /rolldice",
    "attributes": {
        "endpoint": "/rolldice"
    },
    "flags": 1,
    "traceId": "6833b9a4cccf4d9bfb82b11686fd8f63",
    "spanId": "bd19f2fcbc107755"
}

@liustve liustve requested a review from a team as a code owner May 27, 2025 05:38
@liustve liustve requested a review from jj22ee May 27, 2025 05:46
@liustve
Copy link
Contributor Author

liustve commented May 28, 2025

Closing in favor of #181

@liustve liustve closed this May 28, 2025
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.

1 participant