Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

feat(spanner): implement custom tracer_provider injection for opentelemetry traces - #1229

Merged
harshachinta merged 19 commits into
googleapis:mainfrom
odeke-em:tracer_provider-injection
Nov 15, 2024
Merged

feat(spanner): implement custom tracer_provider injection for opentelemetry traces#1229
harshachinta merged 19 commits into
googleapis:mainfrom
odeke-em:tracer_provider-injection

Conversation

@odeke-em

Copy link
Copy Markdown
Contributor

An important feature for observability is to allow the injection of a custom tracer_provider instead of always using the global tracer_provider.

@odeke-em
odeke-em requested review from a teamNovember 9, 2024 19:22
@product-auto-labelproduct-auto-labelBot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/python-spanner API. labels Nov 9, 2024
@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch 5 times, most recently from eca7d36 to 549cfaaCompareNovember 11, 2024 06:05
@harshachintaharshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 11, 2024
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 11, 2024
@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch 3 times, most recently from 285c578 to 52c4b3bCompareNovember 11, 2024 08:49
@harshachintaharshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 11, 2024
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 11, 2024

@harshachintaharshachinta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation creates a tight coupling between observability_options and session, even though they are unrelated. While this approach achieves the goal and simplifies the code (since it assumes a session is available in every method), and assigning observability_options to the session can make retrieval easier, it may lead to confusion for future developers.

I propose following the approach used in other languages. We should set observability_options at the transaction level whenever a transaction is created in database.py. Specifically, observability_options would be accessible in database.py, where customers call methods like snapshot(), batch(), and run_in_transaction(). These methods have base classes, such as _SnapshotBase, _BatchBase, etc. The observability_options would be set at this class level, and methods within these classes would access the options directly from the class whenever trace_call is invoked.

Comment threadgoogle/cloud/spanner_v1/_opentelemetry_tracing.py
Comment threadgoogle/cloud/spanner_v1/_opentelemetry_tracing.py Outdated
Comment threadgoogle/cloud/spanner_v1/_opentelemetry_tracing.py Outdated
Comment threadgoogle/cloud/spanner_v1/_opentelemetry_tracing.py Outdated
Comment threadgoogle/cloud/spanner_v1/client.py Outdated
Comment threadgoogle/cloud/spanner_v1/instance.py Outdated
Comment threadgoogle/cloud/spanner_v1/instance.py Outdated
Comment threadgoogle/cloud/spanner_v1/pool.py Outdated
Comment threadgoogle/cloud/spanner_v1/pool.py Outdated
Comment threadgoogle/cloud/spanner_v1/pool.py Outdated
@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch from 67adff0 to fef29eaCompareNovember 12, 2024 06:02
@odeke-em

Copy link
Copy Markdown
ContributorAuthor

Awesome and thank you very much @harshachinta for the insightful review! Roger that, I have made the updates to just infer observability_options from Instance itself. Please take another look. Thank you!

@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch 3 times, most recently from 75a165a to 3d35c4dCompareNovember 12, 2024 06:09
@odeke-em

Copy link
Copy Markdown
ContributorAuthor

@harshachinta so a compromise/meet-in-the-middle would being able to just infer it directly from the Client instead of plumbing all within Transaction creator. I mention this because having made the proposed change within database for where transactions are createdd, it is firstly much more code but also requires much more plumbing inside for example database.run_in_transaction for which then has to also modify session.run_in_transaction instead of simply just inside trace_call retrieving it from session._database.observability_options.

@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch 3 times, most recently from 3c3ed5a to 529d7c8CompareNovember 12, 2024 07:42
Comment threadgoogle/cloud/spanner_v1/client.py
Comment threadgoogle/cloud/spanner_v1/database.py Outdated
Comment threadgoogle/cloud/spanner_v1/snapshot.py Outdated
Comment threadgoogle/cloud/spanner_v1/snapshot.py
Comment threadgoogle/cloud/spanner_v1/transaction.py Outdated
Comment threadgoogle/cloud/spanner_v1/_opentelemetry_tracing.py Outdated
Comment threadgoogle/cloud/spanner_v1/_opentelemetry_tracing.py Outdated
Comment threadtests/unit/test__opentelemetry_tracing.py Outdated
Comment threadgoogle/cloud/spanner_v1/client.py
@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch from 8d3ca28 to 8c5b50bCompareNovember 14, 2024 14:20
@odeke-em

Copy link
Copy Markdown
ContributorAuthor

Thank you for the review feedback @harshachinta! Kindly help me refresh the bots and take a look again, we should be go to go.

@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch from 8c5b50b to 165fdfdCompareNovember 14, 2024 14:30
@harshachintaharshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 14, 2024
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 14, 2024
@odeke-em
odeke-emforce-pushed the tracer_provider-injection branch from 165fdfd to 196e9a0CompareNovember 14, 2024 18:11
@harshachintaharshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 14, 2024
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 14, 2024
@harshachintaharshachinta changed the title all: implement custom tracer_provider injectionfeat(spanner): implement custom tracer_provider injection for opentelemetry tracesNov 15, 2024
@harshachinta
harshachinta merged commit 6869ed6 into googleapis:mainNov 15, 2024
@release-pleaserelease-pleaseBot mentioned this pull request Nov 15, 2024
@odeke-em
odeke-em deleted the tracer_provider-injection branch November 15, 2024 04:29
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spannerIssues related to the googleapis/python-spanner API.size: lPull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@odeke-em@harshachinta@c24t@yoshi-kokoro