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

[ci-visibility] Implement driver-agnostic integration with CI Visibility #2639

Merged
merged 8 commits into from
Apr 3, 2024

Conversation

nikita-tkachenko-datadog
Copy link
Contributor

@nikita-tkachenko-datadog nikita-tkachenko-datadog commented Mar 11, 2024

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

  • Get the ci visibility test_execution_id from cookie (it will be set by CI Visibility logic in the Datadog tracers using Selenium integration).
  • Create a cookieObservable that uses the cookieStore API to be notified when the ci visibility cookie is set

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@bits-bot
Copy link

bits-bot commented Mar 11, 2024

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Mar 15, 2024

Codecov Report

Attention: Patch coverage is 98.27586% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.36%. Comparing base (282082c) to head (cbe079f).
Report is 5 commits behind head on main.

Files Patch % Lines
packages/rum-core/src/browser/cookieObservable.ts 95.83% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@juan-fernandez juan-fernandez left a 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 :)

packages/rum-core/src/domain/contexts/ciTestContext.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@juan-fernandez juan-fernandez left a 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

Copy link

cit-pr-commenter bot commented Mar 18, 2024

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 155.43 KiB 156.11 KiB 689 B +0.43%
Logs 55.34 KiB 55.34 KiB 0 B 0.00%
Rum Slim 101.93 KiB 102.60 KiB 689 B +0.66%
Worker 25.21 KiB 25.21 KiB 0 B 0.00%

@nikita-tkachenko-datadog nikita-tkachenko-datadog marked this pull request as ready for review March 18, 2024 14:50
@nikita-tkachenko-datadog nikita-tkachenko-datadog requested a review from a team as a code owner March 18, 2024 14:50
@amortemousque amortemousque force-pushed the nikita-tkachenko/rum-ci-visibility-integration branch from fdff5c5 to cb85d18 Compare March 28, 2024 11:00
Copy link
Contributor

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)

@amortemousque amortemousque force-pushed the nikita-tkachenko/rum-ci-visibility-integration branch from 70c2bfe to 08a9e0e Compare March 28, 2024 13:33
@amortemousque amortemousque force-pushed the nikita-tkachenko/rum-ci-visibility-integration branch from 08a9e0e to 365b8a5 Compare March 28, 2024 13:40
packages/rum-core/test/mockCiVisibilityValues.ts Outdated Show resolved Hide resolved
packages/rum-core/src/browser/cookieObservable.ts Outdated Show resolved Hide resolved
packages/rum-core/src/browser/cookieObservable.ts Outdated Show resolved Hide resolved
Comment on lines 37 to 46
event.changed
.concat(event.deleted)
.filter((change) => change.name === cookieName)
.forEach((change) => {
callback({
name: change.name,
value: change.value,
})
})
})
Copy link
Contributor

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?

Copy link
Contributor

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'
})

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done:

// 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/browser/cookieObservable.ts Outdated Show resolved Hide resolved
packages/rum-core/src/browser/cookieObservable.spec.ts Outdated Show resolved Hide resolved
Comment on lines 21 to 27
const detectCookieChangeStrategy = (window as CookieStoreWindow).cookieStore
? listenToCookieStoreChange(configuration)
: watchCookieFallback

return new Observable<CookieChange>((observable) =>
detectCookieChangeStrategy(cookieName, (event) => observable.notify(event))
)
Copy link
Member

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:

Suggested change
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)

Copy link
Contributor

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)

Copy link
Member

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

Copy link
Contributor

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

@amortemousque
Copy link
Contributor

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented Apr 3, 2024

🚂 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 /to-staging -c to cancel this operation!

dd-mergequeue bot added a commit that referenced this pull request Apr 3, 2024
…egration into staging-14

Co-authored-by: Aymeric Mortemousque <aymeric.mortemousque@datadoghq.com>
@dd-devflow
Copy link

dd-devflow bot commented Apr 3, 2024

🚂 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 🦊

@dd-devflow dd-devflow bot added the staging-14 label Apr 3, 2024
@amortemousque amortemousque merged commit 2522989 into main Apr 3, 2024
18 checks passed
@amortemousque amortemousque deleted the nikita-tkachenko/rum-ci-visibility-integration branch April 3, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants