Skip to content

Commit bce2dd7

Browse files
committed
Test gcp auth ext python
1 parent b76119b commit bce2dd7

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

authextension/gcp/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Auth extensions for python auto instrumentation.

authextension/gcp/pyproject.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "opentelemetry-instrumentation-auth-extension"
7+
dynamic = ["version"]
8+
description = "OpenTelemetry auth extension"
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+
]
31+
32+
[project.entry-points.opentelemetry_auth_header_extension]
33+
gcp-auth = "opentelemetry.auth.gcp:GCPAuthHeaderSetter"
34+
35+
[tool.hatch.version]
36+
path = "src/opentelemetry/auth/gcp/version.py"
37+
38+
[tool.hatch.build.targets.sdist]
39+
include = [
40+
"/src",
41+
]
42+
43+
[tool.hatch.build.targets.wheel]
44+
packages = ["src/opentelemetry"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import Tuple
2+
3+
import google.auth
4+
from google.auth.transport import requests
5+
6+
from opentelemetry.exporter.otlp.proto.grpc.exporter import (
7+
BaseAuthHeaderSetter,
8+
)
9+
10+
11+
class GCPAuthHeaderSetter(BaseAuthHeaderSetter):
12+
def __init__(self):
13+
self._credentials, _ = google.auth.default() # type: ignore
14+
self._request = requests.Request()
15+
16+
def get_auth_header(self) -> Tuple[str, str]:
17+
if self._credentials.expired: # type: ignore
18+
self._credentials.refresh(self._request) # type: ignore
19+
return ("Authorization", f"Bearer: {self._credentials.token}") # type: ignore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.52b0.dev"

0 commit comments

Comments
 (0)