generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 27
SigV4 Authentication Support for OTLP HTTP Logs Exporter #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dd37193
implement sigv4 support for logs exporter
liustve 4613dbf
add otlp logs exporter sigv4 support
liustve 52a32a8
deleted base otlp aws class and added aws auth session
liustve 329007f
removed print
liustve 529079c
add unit testing + formatting
liustve ec855cc
linting fix
liustve cde87a6
lint fix
liustve efafc4b
linting fix
liustve a6f4a0b
linting fix
liustve 8241661
added configurator unit tests
liustve 69d225c
lint fix
liustve 03877f1
removed aws span and logs exporter
liustve 4ad4435
default to gzip compression
liustve 6c396db
default to gzip compression
liustve 97b2bb5
add underscore for private helper methods and comment for why we enab…
liustve 4f4dae0
lint fix
liustve 701aaec
Merge branch 'main' into sigv4_logs
liustve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
89 changes: 89 additions & 0 deletions
89
...metry-distro/src/amazon/opentelemetry/distro/exporter/otlp/aws/common/aws_auth_session.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import logging | ||
|
|
||
| import requests | ||
|
|
||
| from amazon.opentelemetry.distro._utils import is_installed | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AwsAuthSession(requests.Session): | ||
| """ | ||
| A custom requests Session that adds AWS SigV4 authentication to HTTP requests. | ||
|
|
||
| This class extends the standard requests.Session to automatically sign requests | ||
| with AWS Signature Version 4 (SigV4) authentication. It's specifically designed | ||
| for use with the OpenTelemetry Logs and Traces exporters that send data to AWS OTLP endpoints: | ||
| X-Ray (traces) and CloudWatch Logs. | ||
|
|
||
| The session requires botocore to be installed for signing headers. If botocore | ||
| is not available, the session will fall back to standard unauthenticated requests | ||
| and log an error message. | ||
|
|
||
| Usage: | ||
| session = AwsAuthSession(aws_region="us-west-2", service="logs") | ||
| response = session.request("POST", "https://logs.us-west-2.amazonaws.com/v1/logs", | ||
| data=payload, headers=headers) | ||
|
|
||
| Args: | ||
| aws_region (str): The AWS region to use for signing (e.g., "us-east-1") | ||
| service (str): The AWS service name for signing (e.g., "logs" or "xray") | ||
| """ | ||
|
|
||
| def __init__(self, aws_region, service): | ||
|
|
||
| self._has_required_dependencies = False | ||
|
|
||
| # Requires botocore to be installed to sign the headers. However, | ||
| # some users might not need to use this authenticator. In order not conflict | ||
| # with existing behavior, we check for botocore before initializing this exporter. | ||
|
|
||
| if aws_region and service and is_installed("botocore"): | ||
| # pylint: disable=import-outside-toplevel | ||
| from botocore import auth, awsrequest, session | ||
|
|
||
| self._boto_auth = auth | ||
| self._boto_aws_request = awsrequest | ||
| self._boto_session = session.Session() | ||
|
|
||
| self._aws_region = aws_region | ||
| self._service = service | ||
| self._has_required_dependencies = True | ||
|
|
||
| else: | ||
| _logger.error( | ||
| "botocore is required to enable SigV4 Authentication. Please install it using `pip install botocore`", | ||
| ) | ||
|
|
||
| super().__init__() | ||
|
|
||
| def request(self, method, url, *args, data=None, headers=None, **kwargs): | ||
| if self._has_required_dependencies: | ||
|
|
||
| credentials = self._boto_session.get_credentials() | ||
|
|
||
| if credentials is not None: | ||
| signer = self._boto_auth.SigV4Auth(credentials, self._service, self._aws_region) | ||
|
|
||
| request = self._boto_aws_request.AWSRequest( | ||
| method="POST", | ||
| url=url, | ||
| data=data, | ||
| headers={"Content-Type": "application/x-protobuf"}, | ||
| ) | ||
|
|
||
| try: | ||
| signer.add_auth(request) | ||
|
|
||
| if headers is None: | ||
| headers = {} | ||
|
|
||
| headers.update(dict(request.headers)) | ||
|
|
||
| except Exception as signing_error: # pylint: disable=broad-except | ||
| _logger.error("Failed to sign request: %s", signing_error) | ||
|
|
||
| return super().request(method=method, url=url, *args, data=data, headers=headers, **kwargs) |
100 changes: 0 additions & 100 deletions
100
aws-opentelemetry-distro/src/amazon/opentelemetry/distro/otlp_aws_span_exporter.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.