-
Notifications
You must be signed in to change notification settings - Fork 142
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
[ci-visibility] Implement driver-agnostic integration with CI Visibility #2639
[ci-visibility] Implement driver-agnostic integration with CI Visibility #2639
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2639 +/- ##
==========================================
+ Coverage 93.34% 93.36% +0.02%
==========================================
Files 238 239 +1
Lines 6922 6966 +44
Branches 1522 1535 +13
==========================================
+ Hits 6461 6504 +43
- Misses 461 462 +1 ☔ View full report in Codecov by Sentry. |
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.
LGTM. Let's see what the rum-browser team thinks :)
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.
you might also need to modify packages/rum-core/test/mockCiVisibilityWindowValues.ts
which is used in a couple of tests packages/rum-core/src/domain/contexts/ciTestContext.spec.ts
and packages/rum-core/src/domain/assembly.spec.ts
Bundles Sizes Evolution
|
fdff5c5
to
cb85d18
Compare
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.
The goal is to use this observable to also watch the session cookie. (in a following PR)
70c2bfe
to
08a9e0e
Compare
08a9e0e
to
365b8a5
Compare
packages/rum-core/src/domain/contexts/ciVisibilityContext.spec.ts
Outdated
Show resolved
Hide resolved
event.changed | ||
.concat(event.deleted) | ||
.filter((change) => change.name === cookieName) | ||
.forEach((change) => { | ||
callback({ | ||
name: change.name, | ||
value: change.value, | ||
}) | ||
}) | ||
}) |
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.
❓ question: are we sure that we can't have ordering issues if a single event contains multiple changes of a single cookie?
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 tried with the both JS APIs but I never managed to get the same cookie twice in the same table. In fact, I got one change event for each API calls:
cookieStore.addEventListener('change', (event) => {
if ((event.changed || []).some((c) => c.name === 'datadog-ci-visibility-test-execution-id')) {
console.log(event.changed)
}
})
document.cookie = 'datadog-ci-visibility-test-execution-id=foo; SameSite=None; Secure'
document.cookie = 'datadog-ci-visibility-test-execution-id=bar; SameSite=None; Secure'
document.cookie = 'datadog-ci-visibility-test-execution-id=baz; SameSite=None; Secure'
cookieStore.set({
name: 'datadog-ci-visibility-test-execution-id',
value: 'foo'
})
cookieStore.set({
name: 'datadog-ci-visibility-test-execution-id',
value: 'bar'
})
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 could not find a clear answer to this question in the spec. So I asked for clarification. However I don't think it's a blocker for the current usage of the observable since the datadog-ci-visibility-test-execution-id
will only be set once. Wdyt?
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.
Sure, it could be nice to add a comment in the implementation though.
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.
Done:
browser-sdk/packages/rum-core/src/browser/cookieObservable.ts
Lines 37 to 38 in 6141054
// Based on our experimentation, we're assuming that entries for the same cookie cannot be in both the 'changed' and 'deleted' arrays. | |
// However, due to ambiguity in the specification, we asked for clarification: https://github.com/WICG/cookie-store/issues/226 |
packages/rum-core/src/domain/contexts/ciVisibilityContext.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/contexts/ciVisibilityContext.spec.ts
Outdated
Show resolved
Hide resolved
const detectCookieChangeStrategy = (window as CookieStoreWindow).cookieStore | ||
? listenToCookieStoreChange(configuration) | ||
: watchCookieFallback | ||
|
||
return new Observable<CookieChange>((observable) => | ||
detectCookieChangeStrategy(cookieName, (event) => observable.notify(event)) | ||
) |
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.
🥜 nitpick: For the sake of readability, I would rewrite this like that:
const detectCookieChangeStrategy = (window as CookieStoreWindow).cookieStore | |
? listenToCookieStoreChange(configuration) | |
: watchCookieFallback | |
return new Observable<CookieChange>((observable) => | |
detectCookieChangeStrategy(cookieName, (event) => observable.notify(event)) | |
) | |
return new Observable<CookieChange>((observable) => { | |
if ((window as CookieStoreWindow).cookieStore) { | |
return listenToCookieStoreChange(configuration, cookieName, observable.notify) | |
} | |
return watchCookieFallback(cookieName, observable.notify) | |
}) |
Reasoning: this removes a few indirections ('Strategy' variable, currying/intermediary function)
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 was pretty much doing what you suggest, but I changed because of this comment: #2639 (comment)
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.
Clarity is subjective, I stand by my opinion, but feel free to dismiss 😃 This is just a nitpick
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.
Indeed it is subjective 🙂 @bcaudan is not here to come to an agreement so let's keep it as is and revisite later if needed
/to-staging |
🚂 Branch Integration: starting soon, merge in < 0s Commit cbe079f557 will soon be integrated into staging-14. This build is going to start soon! (estimated merge in less than 0s) Use |
🚂 Branch Integration: This commit was successfully integrated Commit cbe079f557 has been merged into staging-14 in merge commit 0a14c669f5. Check out the triggered pipeline on Gitlab 🦊 |
Motivation
Allow CI Visibility users who use Selenium for testing their RUM-enabled pages to have their RUM sessions linked to their test executions.
Changes
test_execution_id
from cookie (it will be set by CI Visibility logic in the Datadog tracers using Selenium integration).cookieObservable
that uses the cookieStore API to be notified when the ci visibility cookie is setTesting
I have gone over the contributing documentation.