Skip to content
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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

angelotessaro
Copy link

Description

#2177

Fixes # 2177

Type of change

Please delete options that are not relevant.

  • 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:
  • 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 angelotessaro requested a review from a team February 18, 2024 20:49
Copy link

linux-foundation-easycla bot commented Feb 18, 2024

CLA Missing ID CLA Not Signed

@@ -66,6 +66,7 @@ class PrometheusRemoteWriteMetricsExporter(MetricExporter):
timeout: timeout for remote write requests in seconds, defaults to 30 (Optional)
proxies: dict mapping request proxy protocols to proxy urls (Optional)
tls_config: configuration for remote write TLS settings (Optional)
auth: auth tuple or callable to enable Basic/Digest/Custom HTTP Auth (Optional)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callable should be compatible with requests though, so it should take a requests' Request as parameter and set whatever header is required. The problem with that though is that it'll leak the implementation. So maybe is it better to expand the documentation of the exporter to add an example on how to add authentication using just headers instead?

@ocelotl
Copy link
Contributor

ocelotl commented Jun 28, 2024

@angelotessaro please sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants