Repository navigation
feat(telemetry): tee spans to OTEL_EXPORTER_OTLP_ENDPOINT #7552
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,8 @@ def get_gcp_exporters( | |
| if enable_cloud_tracing: | ||
| span_processor = _get_gcp_span_exporter(credentials) | ||
| span_processors.append(span_processor) | ||
| if user_span_processor := _maybe_get_configured_otlp_span_processor(): | ||
| span_processors.append(user_span_processor) | ||
|
|
||
| metric_readers: list[MetricReader] = [] | ||
| if enable_cloud_metrics: | ||
|
|
@@ -160,6 +162,31 @@ def get_gcp_exporters( | |
| ) | ||
|
|
||
|
|
||
| def _maybe_get_configured_otlp_span_processor() -> Optional[SpanProcessor]: | ||
| """Returns a span processor for a user-configured OTLP endpoint, or None when | ||
| OTEL_EXPORTER_OTLP_(TRACES_)ENDPOINT is not set. | ||
|
|
||
| Lets an existing OTLP pipeline receive spans alongside the GCP exporters. The | ||
| OTLPSpanExporter reads OTEL_EXPORTER_OTLP_* (endpoint, headers, timeout) | ||
| itself; this only wires it into the provider. | ||
| """ | ||
| if not ( | ||
| os.environ.get("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") | ||
| or os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT") | ||
| ): | ||
| return None | ||
| try: | ||
| from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
| except (ImportError, AttributeError): | ||
| logger.warning( | ||
| "OTEL_EXPORTER_OTLP_ENDPOINT is set but" | ||
| " opentelemetry-exporter-otlp-proto-http is not installed;" | ||
| " skipping the additional OTLP span exporter." | ||
| ) | ||
| return None | ||
| return BatchSpanProcessor(OTLPSpanExporter()) | ||
|
Comment on lines
+165
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| def _get_gcp_span_exporter(credentials: Credentials) -> SpanProcessor: | ||
| """Adds OTEL span exporter to telemetry.googleapis.com""" | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is redundant and introduces a bug where spans are exported twice to the configured OTLP endpoint.\n\nIn
src/google/adk/telemetry/setup.py, themaybe_set_otel_providersfunction already automatically appends generic OTel exporters (including the OTLP span exporter) by calling_get_otel_exporters():\n\npython\n # Add generic OTel exporters based on OTel env variables.\n hooks_to_setup.append(_get_otel_exporters())\n\n\nIf a user configuresOTEL_EXPORTER_OTLP_ENDPOINTand callsmaybe_set_otel_providers([get_gcp_exporters(...)]), bothget_gcp_exportersand_get_otel_exporterswill register aBatchSpanProcessor(OTLPSpanExporter()). This results in duplicate span processors being registered to theTracerProvider, causing every span to be exported twice to the user's OTLP pipeline.\n\nSince the existing setup already correctly tees spans to the standard OTLP endpoint when the environment variables are set, we should revert this change and keepget_gcp_exportersstrictly scoped to GCP-specific exporters.