opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

Add auth parameter on PrometheusRemoteWriteMetricsExporter to enable Custom HTTP authentication like AWS Sigv4

Open angelotessaro opened this issue 1 year ago • 2 comments
trafficstars

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

angelotessaro avatar Feb 18 '24 20:02 angelotessaro