Repository navigation
fix(py/google-cloud): fix metric exporter aggregation, credentials client forwarding, and structlog trace processor - #7097
Closed
huangjeff5 wants to merge 2 commits into
Closed
huangjeff5 wants to merge 2 commits into
huangjeff5 wants to merge 2 commits into
Conversation
…ient forwarding, and structlog trace processor
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors telemetry configuration in genkit-google-cloud to properly resolve Google Cloud credentials and instantiate service clients for tracing, logging, and metrics. It also ensures that the structlog trace context processor is correctly positioned before the final renderer, and that the metric exporter preserves aggregation temporality. Feedback suggests improving project ID resolution by using the new _get_google_credentials() helper to extract the project ID from both dictionary and pre-instantiated credentials objects.
Contributor
Author
|
Closing: migrated to standalone repository genkit-ai/genkit-python (PR #38): genkit-ai/genkit-python#38 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
GenkitMetricExporter.__init__did not callsuper().__init__(), leaving_preferred_aggregationunset on the instance.PeriodicExportingMetricReaderthrewAttributeError: 'GenkitMetricExporter' object has no attribute '_preferred_aggregation'.enable_google_cloud_telemetry(credentials=...)forwardedcredentials=...directly intoGenkitGCPExporter(CloudTraceSpanExporter),CloudMonitoringMetricsExporter, andCloudLoggingExporter. None of these accept acredentialskeyword argument, causingTypeError._genkit_inject_trace_contextwas appended toprocessors. Because structlog renderers (ConsoleRenderer,JSONRenderer) transform event dictionaries into strings or bytes, processors appended after them run after rendering or miss log records.Mechanism
super().__init__(): Passpreferred_temporalityand the underlying exporter's_preferred_aggregationsoMetricExporterproperly populates both instance attributes.TraceServiceClient,MetricServiceClient, andLoggingServiceV2Clientinstances with the credentials object whencredentials=is supplied (either as a service account dict or agoogle.auth.credentials.Credentialsinstance), and pass them via theclient=kwarg. Ifprojectis not specified but present in the service account dict, resolveprojectfromcredentials['project_id']._genkit_inject_trace_contextimmediately before the first renderer processor so trace context fields (logging.googleapis.com/trace,spanId) are present inevent_dictwhen rendered.Verification
tests/tracing_test.pycoveringGenkitMetricExporteraggregation temporality preservation, client creation/forwarding undercredentials=, and structlog processor ordering.pytest packages/genkit-google-cloud(225 passed).ruff check,ruff format, andpyrightclean.