You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SigV4 Authentication Support for OTLP HTTP Logs Exporter (#1079)
**Background**
Supporting ADOT auto instrumentation to automatically inject SigV4
authentication headers for outgoing export 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_AWS_LOG_GROUP=[CW-LOG-GROUP-NAME]` **required**~
~`OTEL_AWS_LOG_STREAM=[CW-LOG-STREAM-NAME]` **required**~
`OTEL_EXPORTER_OTLP_LOGS_HEADERS`=`x-aws-log-group=[CW-LOG-GROUP-NAME],x-aws-log-stream=[CW-LOG-STREAM-NAME]`
**required**
`OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=http/protobuf` **required or do not
set env variable**
`OTEL_LOGS_EXPORTER=otlp` **required or do not set env variable**
`OTEL_METRICS_EXPORTER=none`
**Description of changes:**
1. Added new `OtlpAwsLogsExporter` class which uses composition to
extend upstream's `OtlpHttpLogsRecorderExporter` which is responsible
for making the http client calls to export logs to the given endpoint.
2. The `OtlpAwsLogsExporter` customizes the headers by adding an
intermediary step to sign the request with SigV4 authentication and
injects the signed headers to the outgoing logs export request
3. In order to ensure we don't override any user configurations from
environment variables, the `OtlpAwsLogsExporter` constructor copies all
existing `LogsExporter` configurations create by upstream's
instrumentation.
4. The ADOT auto instrumentation is now configured 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 spans in CW Logs.
3. The sample app was run and rerun 30 times and confirmed no issues
with exporting the logs to the endpoint
4. Unit tests were added to verify functionality of OtlpAwsLogsExporter
Further testing will be done with the Release tests.
Example of a log exported using this exporter:
```
{
"resource": {
"attributes": {
"telemetry.distro.version": "0.1.0-aws-SNAPSHOT",
"host.image.id": "ami-0d61ea20f09848335",
"process.command_args": [
"/usr/lib/jvm/java-17-amazon-corretto.x86_64/bin/java",
"-javaagent:aws-opentelemetry-agent-0.1.0-SNAPSHOT.jar",
"-jar",
"springboot-0.1.0-SNAPSHOT.jar"
],
"process.runtime.version": "17.0.14+7-LTS",
"os.type": "linux",
"process.pid": 4921,
"host.type": "t2.large",
"cloud.availability_zone": "us-west-2b",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.language": "java",
"process.runtime.name": "OpenJDK Runtime Environment",
"service.instance.id": "9c190d36-a727-4ae9-b050-5f416b0a30b8",
"os.description": "Linux 5.10.235-227.919.amzn2.x86_64",
"host.arch": "amd64",
"host.name": "ip-172-31-42-50.us-west-2.compute.internal",
"telemetry.sdk.version": "1.44.1",
"cloud.platform": "aws_ec2",
"host.id": "i-0cdb19c9ae754e7b7",
"cloud.region": "us-west-2",
"service.name": "TEST_SERVICE",
"telemetry.distro.name": "opentelemetry-java-instrumentation",
"cloud.provider": "aws",
"cloud.account.id": "571600841604",
"process.executable.path": "/usr/lib/jvm/java-17-amazon-corretto.x86_64/bin/java",
"process.runtime.description": "Amazon.com Inc. OpenJDK 64-Bit Server VM 17.0.14+7-LTS"
}
},
"scope": {
"name": "com.amazon.sampleapp.DemoController"
},
"timeUnixNano": 1745366143259000000,
"observedTimeUnixNano": 1745366143259133756,
"severityNumber": 9,
"severityText": "INFO",
"body": "Executing aws-sdk-call",
"flags": 1,
"traceId": "68082c7f6d9883fcb601f34426c13382",
"spanId": "7cff484e6682e5ea"
}
```
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
if (logsHeaders == null || logsHeaders.isEmpty()) {
63
+
logger.warning(
64
+
"Improper configuration: Please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS to include x-aws-log-group and x-aws-log-stream");
65
+
66
+
returnfalse;
67
+
}
68
+
69
+
longfilteredLogHeaders =
70
+
Arrays.stream(logsHeaders.split(","))
71
+
.filter(
72
+
pair -> {
73
+
if (pair.contains("=")) {
74
+
Stringkey = pair.split("=", 2)[0];
75
+
returnkey.equals(AWS_OTLP_LOGS_GROUP_HEADER)
76
+
|| key.equals(AWS_OTLP_LOGS_STREAM_HEADER);
77
+
}
78
+
returnfalse;
79
+
})
80
+
.count();
81
+
82
+
if (filteredLogHeaders != 2) {
83
+
logger.warning(
84
+
"Improper configuration: Please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS to have values for x-aws-log-group and x-aws-log-stream");
85
+
returnfalse;
86
+
}
87
+
88
+
returntrue;
89
+
}
90
+
91
+
/**
92
+
* Is the given configuration correct to enable SigV4 for Traces?
Copy file name to clipboardExpand all lines: awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsApplicationSignalsCustomizerProvider.java
0 commit comments