Skip to content

Propose way to customize exporters.#4452

Closed
DylanRussell wants to merge 1 commit intoopen-telemetry:mainfrom
DylanRussell:exporter_customizer
Closed

Propose way to customize exporters.#4452
DylanRussell wants to merge 1 commit intoopen-telemetry:mainfrom
DylanRussell:exporter_customizer

Conversation

@DylanRussell
Copy link
Copy Markdown
Contributor

One possible approach to customize OTLP exporters

@DylanRussell
Copy link
Copy Markdown
Contributor Author

DylanRussell commented Feb 27, 2025

This would let us inject a customizer into the code, that would initialize the OTLP exporters with a set of custom params, ex:

import inspect
from typing import Tuple

import google.auth
import grpc
from google.auth.transport import requests
from google.auth.transport.grpc import AuthMetadataPlugin
from google.auth.transport.requests import AuthorizedSession

from opentelemetry.exporter.otlp.customizer import (
    BaseOTLPExporters,
    OTLPExporterCustomizerBase,
)

class GoogleOTLPExporterCustomizer(OTLPExporterCustomizerBase):
    def __init__(self):
        credentials, _ = google.auth.default()
        request = requests.Request()
        auth_metadata_plugin = AuthMetadataPlugin(
            credentials=credentials, request=request
        )

        self.authed_session = AuthorizedSession(credentials)
        self.channel_creds = grpc.composite_channel_credentials(
            grpc.ssl_channel_credentials(),
            grpc.metadata_call_credentials(auth_metadata_plugin),
        )

    def customize_exporter(
        self, exporter_class: BaseOTLPExporters
    ) -> Tuple[str, str]:
        params = inspect.signature(exporter_class.__init__).parameters
        if "credentials" in params and isinstance(
            self.channel_creds, params["credentials"].annotation
        ):
            return exporter_class(credentials=self.channel_creds)
        if "session" in params and isinstance(
            self.authed_session, params["session"].annotation
        ):
            return exporter_class(session=self.authed_session)
        raise RuntimeError(
            "OTLP Exporter class {export_class.__name__} does not contain a parameter named `sesion` or `credentials`."
        )

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Mar 12, 2026
@github-actions
Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

@github-actions github-actions Bot closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant