-
Notifications
You must be signed in to change notification settings - Fork 103
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 Database.batchCreateSessions + SessionPool.createSessions #2145
feat: (observability) trace Database.batchCreateSessions + SessionPool.createSessions #2145
Conversation
This change adds observability tracing for Transaction along with tests. Updates googleapis#2079 Updates googleapis#2114 Requires PR googleapis#2145.
Can you also add record session leaks in opentelemetry traces. Add the this._getLeaks() in traces, also |
692a62c
to
3d6aaf2
Compare
3d6aaf2
to
e600592
Compare
0e5e067
to
385d5c8
Compare
This change adds observability tracing for Transaction along with tests. Updates googleapis#2079 Updates googleapis#2114 Requires PR googleapis#2145.
This change adds observability tracing for Transaction along with tests. Updates googleapis#2079 Updates googleapis#2114 Requires PR googleapis#2145.
…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
385d5c8
to
67d5fbe
Compare
And rebased from main, good to get to bots testing and review updates @alkatrivedi @surbhigarg92! |
src/session-pool.ts
Outdated
@@ -485,6 +491,9 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { | |||
}); | |||
|
|||
this._traces = new Map(); | |||
if (!this._observabilityOptions) { |
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.
Why do we need this if check. We should simply override the observability option ?
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.
Not really, I was being cautious in case someone had passed in multiple observability configurations one for the explicitly created SessionPool and then one for the Database separately. It doesn't hurt to be conservative at the beginning before these libraries have been put into heavy usage.
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.
But we don't allow customers to pass multiple observability configurations right ? They should be able to set it only once via spannerOptions.
We also modified the _observabilityOptions object to add _ to represent private variable.
src/session-pool.ts
Outdated
// will return at most 100 at a time, hence the need for a while loop. | ||
while (amount > 0) { | ||
let sessions: Session[] | null = null; | ||
if (!this.database._observabilityOptions) { |
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.
Why do we need to set. the observability option here again ? We should be doing it in constructor ?
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.
There was some test case in which the observability options for database weren't set despite having been passed into the Spanner constructor.
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.
Then we should find a way to fix those test cases and not add the code here again.
observability-test/spanner.ts
Outdated
|
||
done(); | ||
describe('Regression tests for fixed bugs', () => { |
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.
use a better name to describe the test block. Maybe something like E2E traces with async/await
?
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.
But they are really regression tests, wouldn't E2E be even more obscure? Regression to catch any future bugs given an exact use case per bug.
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.
Also btw within this section I've included the callback variant of that bug reproducer
…ready happened before running
bcac385
to
1dfcfcf
Compare
1dfcfcf
to
bb44c62
Compare
0fc1258
to
1c36d39
Compare
observability-test/spanner.ts
Outdated
// See https://github.com/googleapis/nodejs-spanner/issues/2146. | ||
const traceExporter = new InMemorySpanExporter(); | ||
const provider = new NodeTracerProvider({ | ||
describe('Regression tests for fixed bugs', async () => { |
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.
We can not have test block name as 'Regression tests for fixed bugs' . Block should tell what the scope of testing is.
Create two separate block. One is describe('async/await'
, another describe('callback',
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.
I think I'll defer to you then for the naming as you are the maintainer; this because for other projects we usually have explicit sections for regression tests where it is highly encouraged that you post the reproducers. What name would you like for this?
src/instrument.ts
Outdated
// but we shouldn't make our customers have to invasively edit their code | ||
// nor should they be burdened about these facts, their code should JUST work. | ||
// Please see https://github.com/googleapis/nodejs-spanner/issues/2146 |
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.
I think we should remove this code. As we have added the opentelemetry link which should be enough. The bug will be anyway linked so maintainers would be able to track it using the code blame if required.
src/session-pool.ts
Outdated
@@ -485,6 +491,9 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { | |||
}); | |||
|
|||
this._traces = new Map(); | |||
if (!this._observabilityOptions) { |
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.
But we don't allow customers to pass multiple observability configurations right ? They should be able to set it only once via spannerOptions.
We also modified the _observabilityOptions object to add _ to represent private variable.
src/session-pool.ts
Outdated
// will return at most 100 at a time, hence the need for a while loop. | ||
while (amount > 0) { | ||
let sessions: Session[] | null = null; | ||
if (!this.database._observabilityOptions) { |
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.
Then we should find a way to fix those test cases and not add the code here again.
InMemorySpanExporter, | ||
} = require('@opentelemetry/sdk-trace-node'); | ||
// eslint-disable-next-line n/no-extraneous-require | ||
const {SimpleSpanProcessor} = require('@opentelemetry/sdk-trace-base'); |
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.
Why don't we add @opentelemetry/sdk-trace-base
as a test dependency and remove this lint from everywhere in code
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.
@surbhigarg92 it is added in devDependencies
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.
then why do we need to add this eslint suppress ?
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.
Without it we were getting build failures, it's basically the template for the tests in observability-test from long when we started sending in code changes. I really didn't dig in as it required so much time going through and figuring the build system's problems and it wasn't worth the hours sweating on.
🤖 I have created a release *beep* *boop* --- ## [7.15.0](https://togithub.com/googleapis/nodejs-spanner/compare/v7.14.0...v7.15.0) (2024-10-30) ### Features * (observability, samples): add tracing end-to-end sample ([#2130](https://togithub.com/googleapis/nodejs-spanner/issues/2130)) ([66d99e8](https://togithub.com/googleapis/nodejs-spanner/commit/66d99e836cd2bfbb3b0f78980ec2b499f9e5e563)) * (observability) add spans for BatchTransaction and Table ([#2115](https://togithub.com/googleapis/nodejs-spanner/issues/2115)) ([d51aae9](https://togithub.com/googleapis/nodejs-spanner/commit/d51aae9c9c3c0e6319d81c2809573ae54675acf3)), closes [#2114](https://togithub.com/googleapis/nodejs-spanner/issues/2114) * (observability) Add support for OpenTelemetry traces and allow observability options to be passed. ([#2131](https://togithub.com/googleapis/nodejs-spanner/issues/2131)) ([5237e11](https://togithub.com/googleapis/nodejs-spanner/commit/5237e118befb4b7fe4aea76a80a91e822d7a22e4)), closes [#2079](https://togithub.com/googleapis/nodejs-spanner/issues/2079) * (observability) propagate database name for every span generated to aid in quick debugging ([#2155](https://togithub.com/googleapis/nodejs-spanner/issues/2155)) ([0342e74](https://togithub.com/googleapis/nodejs-spanner/commit/0342e74721a0684d8195a6299c3a634eefc2b522)) * (observability) trace Database.batchCreateSessions + SessionPool.createSessions ([#2145](https://togithub.com/googleapis/nodejs-spanner/issues/2145)) ([f489c94](https://togithub.com/googleapis/nodejs-spanner/commit/f489c9479fa5402f0c960cf896fd3be0e946f182)) * (observability): trace Database.runPartitionedUpdate ([#2176](https://togithub.com/googleapis/nodejs-spanner/issues/2176)) ([701e226](https://togithub.com/googleapis/nodejs-spanner/commit/701e22660d5ac9f0b3e940ad656b9ca6c479251d)), closes [#2079](https://togithub.com/googleapis/nodejs-spanner/issues/2079) * (observability): trace Database.runTransactionAsync ([#2167](https://togithub.com/googleapis/nodejs-spanner/issues/2167)) ([d0fe178](https://togithub.com/googleapis/nodejs-spanner/commit/d0fe178623c1c48245d11bcea97fcd340b6615af)), closes [#207](https://togithub.com/googleapis/nodejs-spanner/issues/207) * Allow multiple KMS keys to create CMEK database/backup ([#2099](https://togithub.com/googleapis/nodejs-spanner/issues/2099)) ([51bc8a7](https://togithub.com/googleapis/nodejs-spanner/commit/51bc8a7445ab8b3d2239493b69d9c271c1086dde)) * **observability:** Fix bugs found from product review + negative cases ([#2158](https://togithub.com/googleapis/nodejs-spanner/issues/2158)) ([cbc86fa](https://togithub.com/googleapis/nodejs-spanner/commit/cbc86fa80498af6bd745eebb9443612936e26d4e)) * **observability:** Trace Database methods ([#2119](https://togithub.com/googleapis/nodejs-spanner/issues/2119)) ([1f06871](https://togithub.com/googleapis/nodejs-spanner/commit/1f06871f7aca386756e8691013602b069697bb87)), closes [#2114](https://togithub.com/googleapis/nodejs-spanner/issues/2114) * **observability:** Trace Database.batchWriteAtLeastOnce ([#2157](https://togithub.com/googleapis/nodejs-spanner/issues/2157)) ([2a19ef1](https://togithub.com/googleapis/nodejs-spanner/commit/2a19ef1af4f6fd1b81d08afc15db76007859a0b9)), closes [#2079](https://togithub.com/googleapis/nodejs-spanner/issues/2079) * **observability:** Trace Transaction ([#2122](https://togithub.com/googleapis/nodejs-spanner/issues/2122)) ([a464bdb](https://togithub.com/googleapis/nodejs-spanner/commit/a464bdb5cbb7856b7a08dac3ff48132948b65792)), closes [#2114](https://togithub.com/googleapis/nodejs-spanner/issues/2114) ### Bug Fixes * Exact staleness timebound ([#2143](https://togithub.com/googleapis/nodejs-spanner/issues/2143)) ([f01516e](https://togithub.com/googleapis/nodejs-spanner/commit/f01516ec6ba44730622cfb050c52cd93f30bba7a)), closes [#2129](https://togithub.com/googleapis/nodejs-spanner/issues/2129) * GetMetadata for Session ([#2124](https://togithub.com/googleapis/nodejs-spanner/issues/2124)) ([2fd63ac](https://togithub.com/googleapis/nodejs-spanner/commit/2fd63acb87ce06a02d7fdfa78d836dbd7ad59a26)), closes [#2123](https://togithub.com/googleapis/nodejs-spanner/issues/2123) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
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