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 11 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
68 changes: 68 additions & 0 deletions
68
...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,68 @@ | ||
| # 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): | ||
|
|
||
| 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 exporter. 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) |
45 changes: 45 additions & 0 deletions
45
...y-distro/src/amazon/opentelemetry/distro/exporter/otlp/aws/logs/otlp_aws_logs_exporter.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,45 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from typing import Dict, Optional | ||
|
|
||
| from amazon.opentelemetry.distro.exporter.otlp.aws.common.aws_auth_session import AwsAuthSession | ||
| from opentelemetry.exporter.otlp.proto.http import Compression | ||
| from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter | ||
|
|
||
|
|
||
| class OTLPAwsLogExporter(OTLPLogExporter): | ||
| """ | ||
| This exporter extends the functionality of the OTLPLogExporter to allow logs to be exported to the | ||
| CloudWatch Logs OTLP endpoint https://logs.[AWSRegion].amazonaws.com/v1/logs. Utilizes the botocore | ||
| library to sign and directly inject SigV4 Authentication to the exported request's headers. | ||
|
|
||
| https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-OTLPEndpoint.html | ||
| """ | ||
|
|
||
| # pylint: disable=too-many-arguments | ||
| def __init__( | ||
| self, | ||
| endpoint: Optional[str] = None, | ||
| certificate_file: Optional[str] = None, | ||
| client_key_file: Optional[str] = None, | ||
| client_certificate_file: Optional[str] = None, | ||
| headers: Optional[Dict[str, str]] = None, | ||
| timeout: Optional[int] = None, | ||
| compression: Optional[Compression] = None, | ||
| ): | ||
| rsession = None | ||
|
|
||
| if endpoint: | ||
| rsession = AwsAuthSession(endpoint.split(".")[1], "logs") | ||
|
|
||
| super().__init__( | ||
| endpoint=endpoint, | ||
| certificate_file=certificate_file, | ||
| client_key_file=client_key_file, | ||
| client_certificate_file=client_certificate_file, | ||
| headers=headers, | ||
| timeout=timeout, | ||
| compression=compression, | ||
| session=rsession, | ||
| ) |
45 changes: 45 additions & 0 deletions
45
...distro/src/amazon/opentelemetry/distro/exporter/otlp/aws/traces/otlp_aws_span_exporter.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,45 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from typing import Dict, Optional | ||
|
|
||
| from amazon.opentelemetry.distro.exporter.otlp.aws.common.aws_auth_session import AwsAuthSession | ||
| from opentelemetry.exporter.otlp.proto.http import Compression | ||
| from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
|
|
||
|
|
||
| class OTLPAwsSpanExporter(OTLPSpanExporter): | ||
| """ | ||
| This exporter extends the functionality of the OTLPSpanExporter to allow spans to be exported to the | ||
| XRay Traces OTLP endpoint https://xray.[AWSRegion].amazonaws.com/v1/traces. Utilizes the botocore | ||
| library to sign and directly inject SigV4 Authentication to the exported request's headers. | ||
|
|
||
| https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-OTLPEndpoint.html | ||
| """ | ||
|
|
||
| # pylint: disable=too-many-arguments | ||
| def __init__( | ||
| self, | ||
| endpoint: Optional[str] = None, | ||
| certificate_file: Optional[str] = None, | ||
| client_key_file: Optional[str] = None, | ||
| client_certificate_file: Optional[str] = None, | ||
| headers: Optional[Dict[str, str]] = None, | ||
| timeout: Optional[int] = None, | ||
| compression: Optional[Compression] = None, | ||
| ): | ||
| rsession = None | ||
|
|
||
| if endpoint: | ||
| rsession = AwsAuthSession(endpoint.split(".")[1], "xray") | ||
|
|
||
| super().__init__( | ||
| endpoint=endpoint, | ||
| certificate_file=certificate_file, | ||
| client_key_file=client_key_file, | ||
| client_certificate_file=client_certificate_file, | ||
| headers=headers, | ||
| timeout=timeout, | ||
| compression=compression, | ||
| session=rsession, | ||
| ) |
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.