Skip to content

Commit cb5b1a7

Browse files
feat(executors): add GCP telemetry support
1 parent 97be16f commit cb5b1a7

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

libs/executors/garf_executors/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def setup_executor(
5757
'ApiExecutionContext',
5858
]
5959

60-
__version__ = '0.2.2'
60+
__version__ = '0.2.3'

libs/executors/garf_executors/entrypoints/tracer.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -35,8 +35,23 @@ def initialize_tracer():
3535
tracer_provider = TracerProvider(resource=resource)
3636

3737
if otel_endpoint := os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT'):
38-
otlp_processor = BatchSpanProcessor(
39-
OTLPSpanExporter(endpoint=otel_endpoint, insecure=True)
40-
)
41-
tracer_provider.add_span_processor(otlp_processor)
38+
if gcp_project_id := os.getenv('OTEL_EXPORTER_GCP_PROJECT_ID'):
39+
try:
40+
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
41+
except ImportError as e:
42+
raise ImportError(
43+
'Please install garf_executors with GCP support '
44+
'- `pip install garf_executors[gcp]`'
45+
) from e
46+
47+
cloud_span_processor = BatchSpanProcessor(
48+
CloudTraceSpanExporter(project_id=gcp_project_id)
49+
)
50+
tracer_provider.add_span_processor(cloud_span_processor)
51+
else:
52+
otlp_processor = BatchSpanProcessor(
53+
OTLPSpanExporter(endpoint=otel_endpoint, insecure=True)
54+
)
55+
tracer_provider.add_span_processor(otlp_processor)
56+
4257
trace.set_tracer_provider(tracer_provider)

libs/executors/pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,22 @@ bq=[
4444
"garf-io[bq]",
4545
"pandas",
4646
"google-cloud-logging",
47+
"smart_open[gcs]",
4748
]
4849
sql=[
4950
"garf-io[sqlalchemy]",
5051
"pandas",
5152
]
53+
gcp= [
54+
"opentelemetry-exporter-gcp-trace",
55+
]
5256
server=[
5357
"fastapi[standard]",
5458
"opentelemetry-instrumentation-fastapi",
5559
"typer",
5660
]
5761
all = [
58-
"garf-executors[bq,sql,server]"
62+
"garf-executors[bq,sql,server,gcp]"
5963
]
6064
[project.scripts]
6165
garf="garf_executors.entrypoints.cli:main"

0 commit comments

Comments
 (0)