opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Add auth parameter on PrometheusRemoteWriteMetricsExporter to enable Custom HTTP authentication like AWS Sigv4
Description
https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2177
Fixes # 2177
Type of change
Please delete options that are not relevant.
- [X] New feature (non-breaking change which adds functionality)
- [ ] This change requires a documentation update
How Has This Been Tested?
Used custom AWS Sigv4 authentication object to export metrics to Amazon Managed Prometheus service directly, as the following code:
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.exporter.prometheus_remote_write import (
PrometheusRemoteWriteMetricsExporter,
)
from requests_auth_aws_sigv4 import AWSSigV4
aws_auth = AWSSigV4('aps',
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region='eu-west-1',
)
exporter = PrometheusRemoteWriteMetricsExporter(
endpoint='REMOTE_WRITE_ENDPOINT',
headers={},
auth=aws_auth,
)
reader = PeriodicExportingMetricReader(exporter, 1000)
provider = MeterProvider(metric_readers=[reader])
FlaskInstrumentor().instrument_app(app, meter_provider=provider)
Does This PR Require a Core Repo Change?
- [ ] Yes. - Link to PR:
- [X] No.
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
- [ ] Followed the style guidelines of this project
- [ ] Changelogs have been updated
- [ ] Unit tests have been added
- [ ] Documentation has been updated
- :white_check_mark: login: ocelotl / name: Diego Hurtado (7119a8636a0f3a8b5719800181b3035f1e13a137)
- :x: The email address for the commit (0691243c78fc070b7fb710c3d4760d0e68df6e00) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please submit a support request ticket.
@angelotessaro please sign the CLA