Skip to content

fix(py/google-cloud): fix metric exporter aggregation, credentials client forwarding, and structlog trace processor - #38

Merged
huangjeff5 merged 4 commits into
mainfrom
fix/py-gcp-telemetry-exporter
Nov 9, 2026
Merged

huangjeff5 merged 4 commits into
mainfrom
fix/py-gcp-telemetry-exporter

Conversation

@huangjeff5

Copy link
Copy Markdown
Collaborator

Problem

  1. Metric exporter aggregation crash: GenkitMetricExporter.__init__ did not call super().__init__(), leaving _preferred_aggregation unset on the instance. PeriodicExportingMetricReader threw AttributeError: 'GenkitMetricExporter' object has no attribute '_preferred_aggregation'.
  2. Credentials forwarding crash: enable_google_cloud_telemetry(credentials=...) forwarded credentials=... directly into GenkitGCPExporter (CloudTraceSpanExporter), CloudMonitoringMetricsExporter, and CloudLoggingExporter. None of these accept a credentials keyword argument, causing TypeError.
  3. Structlog trace context placement: _genkit_inject_trace_context was appended to processors. Because structlog renderers (ConsoleRenderer, JSONRenderer) transform event dictionaries into strings or bytes, processors appended after them run after rendering or miss log records.

Mechanism

  1. Call super().__init__(): Pass preferred_temporality and the underlying exporter's _preferred_aggregation so MetricExporter properly populates both instance attributes.
  2. Client factory via credentials: Construct typed TraceServiceClient, MetricServiceClient, and LoggingServiceV2Client instances with the credentials object when credentials= is supplied (either as a service account dict or a google.auth.credentials.Credentials instance), and pass them via the client= kwarg. If project is not specified but present in the service account dict, resolve project from credentials['project_id'].
  3. Insert before renderers: Inspect existing structlog processors and insert _genkit_inject_trace_context immediately before the first renderer processor so trace context fields (logging.googleapis.com/trace, spanId) are present in event_dict when rendered.

Verification

  • Added 3 unit tests in tests/tracing_test.py covering GenkitMetricExporter aggregation temporality preservation, client creation/forwarding under credentials=, and structlog processor ordering.
  • Ran pytest packages/genkit-google-cloud (225 passed).
  • Verified ruff check, ruff format, and pyright clean.

@huangjeff5
huangjeff5 force-pushed the fix/py-gcp-telemetry-exporter branch from 267c293 to 3a9838f Compare November 9, 2026 20:17
@huangjeff5
huangjeff5 merged commit 2074db4 into main Nov 9, 2026
20 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-gcp-telemetry-exporter branch November 9, 2026 21:19
huangjeff5 added a commit that referenced this pull request Nov 9, 2026
…tials client forwarding, and structlog trace processor (#38)"

This reverts commit 2074db4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant