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

[Execution Context] Update on URL change #200785

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

afharo
Copy link
Member

@afharo afharo commented Nov 19, 2024

Summary

Resolves #195778

This PR attempts to fix #195778 and https://github.com/elastic/observability-dev/issues/3776 by calling executionContext.set({ url }) whenever we identify the pathname has changed (using the history module for that).

Hopefully, this will remove the need of plugins explicitly calling the execution context to update the path when their internal Router applies any changes.

Checklist

Identify risks

  • The solution is using executionContext.set instead of executionContext.clear. The difference is that any previous contextual information will be kept. When switching apps, we clear every previous context. However, when inside the same app, it didn't feel right to clear everything. Should it?

@afharo afharo added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Team:obs-knowledge Observability Experience Knowledge team labels Nov 19, 2024
@afharo afharo self-assigned this Nov 19, 2024
@elasticmachine
Copy link
Contributor

elasticmachine commented Nov 19, 2024

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!

@afharo
Copy link
Member Author

afharo commented Nov 20, 2024

/ci

@elasticmachine
Copy link
Contributor

elasticmachine commented Nov 20, 2024

💔 Build Failed

Failed CI Steps

History

cc @afharo

@Dosant
Copy link
Contributor

Dosant commented Nov 20, 2024

@afharo, thank for looking into it!

Not sure I understand how this helps, I might be missing something here

I thought that we already reported the correct url from here:

The problem with #195778 is that we don't report pageName that could be useful for segmentation in https://github.com/elastic/observability-dev/issues/3776

so, for example, in the url we'd get the actual URL with dynamic params: service/apm/transactions or service/frontend/transactions, but what would be useful is to have service/:serviceName/transactions which is how it was supposed to be reported in pageName if not the broken #195778

@afharo
Copy link
Member Author

afharo commented Nov 20, 2024

I thought that we already reported the correct url from here:

You are correct! The URL is correctly updated there, but the executionContext only updates it automatically when the app changes.

However, when the URL changes, we don't update it.

The problem with #195778 is that we don't report pageName that could be useful for segmentation in elastic/observability-dev#3776

so, for example, in the url we'd get the actual URL with dynamic params: service/apm/transactions or service/frontend/transactions, but what would be useful is to have service/:serviceName/transactions which is how it was supposed to be reported in pageName if not the broken #195778

That's a great point! My PR would only update the path on URL changes providing the full path (service/apm/transactions), but we may want more generic paths.

I wonder if this is a good fallback, but it still requires the ReactRouter to override this when necessary. WDYT?

@Dosant
Copy link
Contributor

Dosant commented Nov 21, 2024

You are correct! The URL is correctly updated there, but the executionContext only updates it automatically when the app changes.
However, when the URL changes, we don't update it.

Aha, so

return {
type: 'application',
name: this.appId,
url: window.location.pathname,

is not called on every sent event? instead it is called only when executioncontext.set is called?
Then maybe instead of listening to history, we should always call getDefaultContext() to re-evaluate it. wdyt? then we don't need to listen to history. or it is more difficult?

@afharo
Copy link
Member Author

afharo commented Nov 21, 2024

we should always call getDefaultContext() to re-evaluate it

Sorry, what do you mean with "always"?

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

Discussed offline. Forget previous questions, history.listen makes sense considering how the system is set up

// Track URL changes to make sure that we reflect the new path name
this.subscription.add(
history.listen((location) => {
start.set({ url: location.pathname });
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be that location.pathname didn't change, right? Maybe worth calling only when has changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:obs-knowledge Observability Experience Knowledge team Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Execution context remains the same on every route change
4 participants