Forwarding AWS CloudWatch Logs to Sentry via the OpenTelemetry Protocol (OTLP)

Learn how to forward AWS CloudWatch logs to Sentry via the OpenTelemetry Protocol (OTLP).

This guide shows you how to collect AWS CloudWatch logs and forward them to Sentry using the OpenTelemetry Collector with the AWS CloudWatch Receiver.

Before you begin, ensure you have:

  • AWS credentials configured with permissions to read CloudWatch logs
  • A Sentry project to send data to

The AWS CloudWatch Receiver is included in the OpenTelemetry Collector Contrib distribution. You'll need to download and install this version, as the standard otelcol binary does not include the AWS CloudWatch Receiver.

Download the latest otelcol-contrib binary from the OpenTelemetry Collector releases page.

The AWS CloudWatch Receiver uses the AWS SDK for authentication, which supports multiple methods including credentials files and EC2 instance metadata (IMDS).

Configure your AWS credentials using the AWS CLI:

Copied
aws configure

This creates a credentials file at ~/.aws/credentials with your access key and secret.

For EC2 environments, attach an IAM role with the CloudWatchLogsReadOnlyAccess policy to your instance.

Your AWS credentials need the following permissions:

  • logs:DescribeLogGroups
  • logs:DescribeLogStreams
  • logs:GetLogEvents

You'll need your Sentry OTLP endpoint and authentication header. These can be found in your Sentry Project Settings under Client Keys (DSN) > OpenTelemetry (OTLP).

Copied
___OTLP_LOGS_URL___

Copied
x-sentry-auth: sentry sentry_key=___PUBLIC_KEY___

Create a configuration file with the AWS CloudWatch Receiver and the OTLP HTTP exporter configured to send logs to Sentry.

For additional configuration options, see the AWS CloudWatch Receiver Documentation.

This configuration automatically discovers and collects logs from all CloudWatch log groups:

config.yaml
Copied
receivers:
  awscloudwatch:
    region: us-east-1
    logs:
      poll_interval: 1m

processors:
  batch:
    send_batch_size: 1024
    send_batch_max_size: 2048
    timeout: "1s"

exporters:
  otlphttp/sentry:
    logs_endpoint: ___OTLP_LOGS_URL___
    headers:
      x-sentry-auth: "sentry sentry_key=___PUBLIC_KEY___"
    compression: gzip
    encoding: proto

service:
  pipelines:
    logs:
      receivers:
        - awscloudwatch
      processors:
        - batch
      exporters:
        - otlphttp/sentry

This configuration discovers log groups matching a specific prefix, useful for collecting logs from specific AWS services like EKS or Lambda:

config.yaml
Copied
receivers:
  awscloudwatch:
    region: us-east-1
    logs:
      poll_interval: 1m
      groups:
        autodiscover:
          limit: 100
          prefix: /aws/lambda/

processors:
  batch:
    send_batch_size: 1024
    send_batch_max_size: 2048
    timeout: "1s"

exporters:
  otlphttp/sentry:
    logs_endpoint: ___OTLP_LOGS_URL___
    headers:
      x-sentry-auth: "sentry sentry_key=___PUBLIC_KEY___"
    compression: gzip
    encoding: proto

service:
  pipelines:
    logs:
      receivers:
        - awscloudwatch
      processors:
        - batch
      exporters:
        - otlphttp/sentry

This configuration collects logs from specific, named log groups:

config.yaml
Copied
receivers:
  awscloudwatch:
    region: us-east-1
    logs:
      poll_interval: 1m
      groups:
        named:
          /aws/lambda/my-function:
          /aws/eks/my-cluster/cluster:

processors:
  batch:
    send_batch_size: 1024
    send_batch_max_size: 2048
    timeout: "1s"

exporters:
  otlphttp/sentry:
    logs_endpoint: ___OTLP_LOGS_URL___
    headers:
      x-sentry-auth: "sentry sentry_key=___PUBLIC_KEY___"
    compression: gzip
    encoding: proto

service:
  pipelines:
    logs:
      receivers:
        - awscloudwatch
      processors:
        - batch
      exporters:
        - otlphttp/sentry

  • Verify your AWS credentials are correctly configured and have the required permissions
  • Ensure the specified AWS region matches where your CloudWatch log groups are located
  • Check that the log group names or prefixes match existing CloudWatch log groups

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").