Skip to content

Commit a4f142b

Browse files
committed
Example exporter customizer.
1 parent bce2dd7 commit a4f142b

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

exportercustomizer/gcp/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OTLP exporter customizer for python auto instrumentation.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "opentelemetry-instrumentation-exporter-customizer-component"
7+
dynamic = ["version"]
8+
description = "OpenTelemetry OTLP exporter customizer"
9+
readme = "README.rst"
10+
license = "Apache-2.0"
11+
requires-python = ">=3.8"
12+
authors = [
13+
{ name = "OpenTelemetry Authors", email = "[email protected]" },
14+
]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: Apache Software License",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.8",
22+
"Programming Language :: Python :: 3.9",
23+
"Programming Language :: Python :: 3.10",
24+
"Programming Language :: Python :: 3.11",
25+
"Programming Language :: Python :: 3.12",
26+
"Programming Language :: Python :: 3.13",
27+
]
28+
dependencies = [
29+
"google-auth ~= 2.38",
30+
"grpcio ~= 1.7",
31+
"opentelemetry-exporter-otlp-proto-grpc ~= 1.3",
32+
"opentelemetry-exporter-otlp-customizer ~= 1.3",
33+
]
34+
35+
[project.entry-points.opentelemetry_otlp_exporter_customizer]
36+
google_otlp_customizer = "opentelemetry.auth.gcp:GoogleOTLPExporterCustomizer"
37+
38+
[tool.hatch.version]
39+
path = "src/opentelemetry/auth/gcp/version.py"
40+
41+
[tool.hatch.build.targets.sdist]
42+
include = [
43+
"/src",
44+
]
45+
46+
[tool.hatch.build.targets.wheel]
47+
packages = ["src/opentelemetry"]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import inspect
2+
from typing import Tuple
3+
4+
import google.auth
5+
import grpc
6+
from google.auth.transport import requests
7+
from google.auth.transport.grpc import AuthMetadataPlugin
8+
from google.auth.transport.requests import AuthorizedSession
9+
10+
from opentelemetry.exporter.otlp.customizer import (
11+
BaseOTLPExporters,
12+
OTLPExporterCustomizerBase,
13+
)
14+
15+
16+
class GoogleOTLPExporterCustomizer(OTLPExporterCustomizerBase):
17+
def __init__(self):
18+
credentials, _ = google.auth.default()
19+
request = requests.Request()
20+
auth_metadata_plugin = AuthMetadataPlugin(
21+
credentials=credentials, request=request
22+
)
23+
24+
self.authed_session = AuthorizedSession(credentials)
25+
self.channel_creds = grpc.composite_channel_credentials(
26+
grpc.ssl_channel_credentials(),
27+
grpc.metadata_call_credentials(auth_metadata_plugin),
28+
)
29+
30+
def customize_exporter(
31+
self, exporter_class: BaseOTLPExporters
32+
) -> Tuple[str, str]:
33+
params = inspect.signature(exporter_class.__init__).parameters
34+
if "credentials" in params and isinstance(
35+
self.channel_creds, params["credentials"].annotation
36+
):
37+
return exporter_class(credentials=self.channel_creds)
38+
if "session" in params and isinstance(
39+
self.authed_session, params["session"].annotation
40+
):
41+
return exporter_class(session=self.authed_session)
42+
raise RuntimeError(
43+
"OTLP Exporter class {export_class.__name__} does not contain a parameter named `sesion` or `credentials`."
44+
)
45+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.52b0.dev"

opentelemetry-instrumentation/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727
]
2828
dependencies = [
2929
"opentelemetry-api ~= 1.4",
30-
"opentelemetry-semantic-conventions == 0.52b0.dev",
30+
"opentelemetry-semantic-conventions == 0.51b0",
3131
"wrapt >= 1.0.0, < 2.0.0",
3232
"packaging >= 18.0",
3333
]

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def run() -> None:
115115
environ["PYTHONPATH"] = pathsep.join(python_path)
116116

117117
executable = which(args.command)
118+
print("running executable")
118119
execl(executable, executable, *args.command_args)
119120

120121

@@ -127,6 +128,7 @@ def initialize():
127128
)
128129

129130
try:
131+
print("loading distro")
130132
distro = _load_distro()
131133
distro.configure()
132134
_load_configurators()

0 commit comments

Comments
 (0)