Skip to content
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

feat(observability): trace Transaction #2122

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

odeke-em
Copy link
Contributor

This change adds observability tracing for
Transaction along with tests.

Updates #2079
Built from PR #2087
Updates #2114

@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: spanner Issues related to the googleapis/nodejs-spanner API. labels Sep 22, 2024
@odeke-em odeke-em force-pushed the trace-Transaction branch 13 times, most recently from 9a48feb to a4e56f3 Compare September 22, 2024 13:29
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Sep 22, 2024
@odeke-em odeke-em force-pushed the trace-Transaction branch 5 times, most recently from b4217d8 to afa5873 Compare September 23, 2024 07:24
@odeke-em odeke-em force-pushed the trace-Transaction branch 3 times, most recently from d8fe92b to 838225e Compare October 1, 2024 08:23
@odeke-em odeke-em marked this pull request as ready for review October 1, 2024 08:23
@odeke-em odeke-em requested review from a team as code owners October 1, 2024 08:23
@product-auto-label product-auto-label bot removed the size: l Pull request size is large. label Oct 1, 2024
odeke-em added a commit to odeke-em/nodejs-spanner that referenced this pull request Oct 7, 2024
…l.createSessions

This change adds tracing for Database.batchCreateSessions
as well as SessionPool.createSessions which was raised
as a big need.
This change is a premise to finishing up tracing Transaction.

While here, also folded in the async/await fix to avoid day+ long
code review lag and then 3+ hours just to run tests per PR:
OpenTelemetry cannot work correctly for async/await if there isn't
a set AsyncHooksManager, but we should not burden our customers with
this type of specialist knowledge, their code should just work and
this change performs such a check. Later on we shall file a feature
request with the OpenTelemetry-JS API group to give us a hook to detect
if we've got a live asyncHooksManager instead of this mandatory
comparison to ROOT_CONTEXT each time.

Fixes googleapis#2146
Updates googleapis#2079
Spun out of PR googleapis#2122
Supersedes PR googleapis#2147
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 7, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 7, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 7, 2024
src/transaction.ts Outdated Show resolved Hide resolved
if (err) {
callback!(err, resp);
return;
const q = {opts: this._observabilityOptions};
Copy link
Contributor

Choose a reason for hiding this comment

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

Also can't we create the observabilityOptions object once in the constructor and use that everywhere, instead of creating it in every method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or atleast create a basic object which can be used everywhere and extend it to the method where its required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes we have to add some attributes to it, sometimes we have newly injected values of this._observabilityOptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

sometimes we have newly injected values of
When will we be having that. IMU this can only be set at the time of spanner creation via spanner options

If we define the basic object in constructor then we can extend that object whereever we need using "Object.assign" . WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say let's keep it as is because as I mentioned there are instances where we copy over _observabilityOptions to an already existing object so keeping it in the constructor is non-kosher.

src/transaction.ts Outdated Show resolved Hide resolved
span.end();
});

if (!prs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what is this check for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are instances where we have an EventEmitter returned that I found in tests, not being returned by the type assertion to PartialResultStream.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please link the test, I am not able to get the reason for this check.

Copy link
Contributor

Choose a reason for hiding this comment

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

@odeke-em Please see this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check was being defensive from some odd condition in earlier changes but now it doesn't fail. However, the others that check is instanceof Stream are valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, thank you @surbhigarg92!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surbhigarg92 actually I found where the problem was and it shows in the test

Transaction
       Snapshot
         createReadStream
           should use the transaction id if present:
     TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of ReadableStream, WritableStream, or Stream. Received undefined

notice the

TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of ReadableStream, WritableStream, or Stream. Received undefined

particularly for
argument must be an instance of ReadableStream, WritableStream, or Stream. Received undefined

src/transaction.ts Outdated Show resolved Hide resolved
src/transaction.ts Outdated Show resolved Hide resolved
src/transaction.ts Outdated Show resolved Hide resolved
observability-test/spanner.ts Show resolved Hide resolved
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 8, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2024
@alkatrivedi alkatrivedi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2024
@surbhigarg92 surbhigarg92 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2024
This change adds observability tracing for
Transaction along with tests.

Updates googleapis#2079
Updates googleapis#2114
Requires PR googleapis#2145.
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2024
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 8, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 8, 2024
@odeke-em
Copy link
Contributor Author

odeke-em commented Oct 8, 2024

Thank you very much for the reviews and approval @surbhigarg92!

@surbhigarg92 surbhigarg92 added the automerge Merge the pull request once unit tests and other checks pass. label Oct 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 8, 2024
@gcf-merge-on-green gcf-merge-on-green bot merged commit a464bdb into googleapis:main Oct 8, 2024
16 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Oct 8, 2024
odeke-em added a commit to odeke-em/nodejs-spanner that referenced this pull request Oct 8, 2024
…l.createSessions

This change adds tracing for Database.batchCreateSessions
as well as SessionPool.createSessions which was raised
as a big need.
This change is a premise to finishing up tracing Transaction.

While here, also folded in the async/await fix to avoid day+ long
code review lag and then 3+ hours just to run tests per PR:
OpenTelemetry cannot work correctly for async/await if there isn't
a set AsyncHooksManager, but we should not burden our customers with
this type of specialist knowledge, their code should just work and
this change performs such a check. Later on we shall file a feature
request with the OpenTelemetry-JS API group to give us a hook to detect
if we've got a live asyncHooksManager instead of this mandatory
comparison to ROOT_CONTEXT each time.

Fixes googleapis#2146
Updates googleapis#2079
Spun out of PR googleapis#2122
Supersedes PR googleapis#2147
gcf-merge-on-green bot pushed a commit that referenced this pull request Oct 10, 2024
…l.createSessions (#2145)

This change adds tracing for Database.batchCreateSessions
as well as SessionPool.createSessions which was raised
as a big need.
This change is a premise to finishing up tracing Transaction.

While here, also folded in the async/await fix to avoid day+ long
code review lag and then 3+ hours just to run tests per PR:
OpenTelemetry cannot work correctly for async/await if there isn't
a set AsyncHooksManager, but we should not burden our customers with
this type of specialist knowledge, their code should just work and
this change performs such a check. Later on we shall file a feature
request with the OpenTelemetry-JS API group to give us a hook to detect
if we've got a live asyncHooksManager instead of this mandatory
comparison to ROOT_CONTEXT each time.

Fixes #2146
Updates #2079
Spun out of PR #2122
Supersedes PR #2147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants