feat: automatic log group/stream creation at startup when using otlphttp exporter for logs#2083
Draft
feat: automatic log group/stream creation at startup when using otlphttp exporter for logs#2083
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the issue
The CloudWatch OTLP Logs endpoint (
https://logs.<region>.amazonaws.com/v1/logs) requires the target log group and log stream to already exist before accepting log data. Unlike the nativePutLogEventsAPI used byawscloudwatchlogsexporter— which auto-creates log groups and streams on first write — theotlphttpexporter sends standard OTLP HTTP requests with no built-in CW resource provisioning.This forces customers to manually pre-create log groups and streams) before CWAgent can export logs via the OTLP path, adding friction to the setup experience.
Description of changes
Adds a
confmap.Converterthat runs during CWAgent's config resolution phase — after the JSON config is translated to OTel YAML but before the OTel pipeline components (receivers, processors, exporters) are started.How it works:
otlphttpandotlphttp/*exporterslogs/*pipelines (viaservice.pipelinescross-reference)logs_endpointorendpointmatches the CW Logs OTLP pattern (https://logs.<region>.amazonaws.com)x-aws-log-groupandx-aws-log-streamfrom the exporter'sheadersconfigCreateLogGroupthenCreateLogStreamvia the AWS SDK (both idempotent —ResourceAlreadyExistsExceptionis silently ignored)Files added:
service/configprovider/otlphttp_log_provisioner.go—confmap.Converterimplementation with config scanning, CW endpoint detection, and log group/stream creationservice/configprovider/otlphttp_log_provisioner_test.go— Unit tests covering: single exporter, exporter not in logs pipeline, non-CW endpoint ignored, missing log group header, default log stream fallback, multiple exporters, empty config, and region extractionFiles modified:
service/configprovider/provider.go— RegisteredNewOTLPHTTPLogProvisionerFactory()in the converter chain afterotlphttpValidatorLicense
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Unit tests:
TestExtractRegionFromLogsEndpoint— validates region extraction from CW Logs OTLP endpoints (us-east-1, eu-west-1, non-logs endpoint, empty, non-AWS endpoint)TestFindLogTargets— validates config scanning logic for when to create log group/stream and when not to based on the configuration.E2E testing:
otelConfigwithotlphttpexporter targeting CW Logs OTLP endpoint withx-aws-log-groupandx-aws-log-streamheadersRequirements
Before commiting your code, please do the following steps.
make fmtandmake fmt-shmake lintIntegration Tests
To run integration tests against this PR, add the
ready for testinglabel.