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

SEARCH_TIME_EVENT is unusable due to plausible and CORS limitations #3775

Closed
1 of 2 tasks
obulat opened this issue Feb 9, 2024 · 7 comments · Fixed by #3779 or #4044
Closed
1 of 2 tasks

SEARCH_TIME_EVENT is unusable due to plausible and CORS limitations #3775

obulat opened this issue Feb 9, 2024 · 7 comments · Fixed by #3779 or #4044
Assignees
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: frontend Related to the Nuxt frontend

Comments

@obulat
Copy link
Contributor

obulat commented Feb 9, 2024

Description

vue-plausible only provides client-side integration, and we cannot send events from the server:

https://github.com/moritzsternemann/vue-plausible/blob/56d05277e4082183c700e9f0df4e82b711a00f07/src/nuxt-module.ts#L22-L27

Note: this has never been the problem before because we never recorded server-side events.

On the other hand, on the client side, due to CORS limitations, we cannot get the required headers (["date", "cf-cache-status", "cf-ray"]). Browser limits JS access to only "cache-control", "content-type" and "last-modified"1.

Reproduction

  1. Open a server-side rendered search page on staging: https://staging.openverse.org/search/?q=cat
  2. See "Whoops, error". In the console, there is a "t is undefined" error logged.
  3. See also that you can search client-side, but the search time event is not logged.

Additional context

The immediate fix for this is to revert the commit in question. This fix is critical because the app's server-side rendered search became unusable.

To correctly send the search time event, we the following two issues need to be opened, with a lower importance label.

Server

Client

Footnotes

  1. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#access-control-expose-headers

@obulat obulat added 🟥 priority: critical Must be addressed ASAP 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository 🧱 stack: frontend Related to the Nuxt frontend labels Feb 9, 2024
@openverse-bot openverse-bot moved this to 📅 To Do in Openverse Backlog Feb 9, 2024
@openverse-bot openverse-bot moved this from 📅 To Do to 📋 Backlog in Openverse Backlog Feb 9, 2024
@openverse-bot openverse-bot moved this from 📋 Backlog to 📅 To Do in Openverse Backlog Feb 9, 2024
@dhruvkb
Copy link
Member

dhruvkb commented Feb 9, 2024

Since it's in staging I don't think reverting the commit should be prioritised over applying the recommended fixes that you have already documented.

@obulat
Copy link
Contributor Author

obulat commented Feb 9, 2024

Since it's in staging I don't think reverting the commit should be prioritised over applying the recommended fixes that you have already documented.

The fixes might take longer than anticipated, and the fix would also depend on the API being deployed, so I think it would be safer to revert.

@openverse-bot openverse-bot moved this from 📅 To Do to 🏗 In Progress in Openverse Backlog Feb 9, 2024
@openverse-bot openverse-bot moved this from 🏗 In Progress to ✅ Done in Openverse Backlog Feb 10, 2024
@openverse-bot openverse-bot moved this from ✅ Done to 📋 Backlog in Openverse Backlog Feb 13, 2024
@openverse-bot openverse-bot moved this from 📋 Backlog to 📅 To Do in Openverse Backlog Feb 13, 2024
@sarayourfriend
Copy link
Collaborator

This isn't fixed, right? Reopened just in case. We've just reverted the thing causing the issue.

@obulat would a simple solution be to wrap sendCustomEvent with a conditional check on process.client and return a noop when on the server? That would be a stop-gap until we implement, if we want, sending event server side (but I don't see that as a requirement).

We don't need SEARCH_TIME_EVENT for server side requests, because those happen within our VPC, they are fast. The event is meant to capture user experience of those requests, to identify the behaviour of the requests after they leave our network.

@obulat
Copy link
Contributor Author

obulat commented Feb 13, 2024

This isn't fixed, right? Reopened just in case. We've just reverted the thing causing the issue.

This issue was split into two. I think it's best to fix the underlying issues, and then re-open the original PR to close this issue

@obulat would a simple solution be to wrap sendCustomEvent with a conditional check on process.client and return a noop when on the server? That would be a stop-gap until we implement, if we want, sending event server side (but I don't see that as a requirement).

I guess we would have to wrap $plausible here:

const { $plausible } = useContext()

So, I think we could use something like

const { $plausible } = process.server ? { $plausible: () => {/** no op*/} } : useContext()

We don't need SEARCH_TIME_EVENT for server side requests, because those happen within our VPC, they are fast. The event is meant to capture user experience of those requests, to identify the behaviour of the requests after they leave our network.

I did not know that we mainly want to measure the client side requests, thank you for this context.

@sarayourfriend
Copy link
Collaborator

I did not know that we mainly want to measure the client side requests, thank you for this context.

Hopefully that lets us find a "good enough for now" aspect of this, and we can address being able to send events on the server side later on, when we actually need them. It's an important limitation to document, though...

@obulat obulat added 🟧 priority: high Stalls work on the project or its dependents and removed 🟥 priority: critical Must be addressed ASAP labels Feb 19, 2024
@obulat
Copy link
Contributor Author

obulat commented Feb 19, 2024

I lowered the priority here because the PR that was breaking the app was reversed.

@obulat obulat added the ⛔ status: blocked Blocked & therefore, not ready for work label Feb 26, 2024
@openverse-bot openverse-bot moved this from 📅 To Do to ⛔ Blocked in Openverse Backlog Feb 26, 2024
@obulat obulat moved this from ⛔ Blocked to 📅 To Do in Openverse Backlog Mar 25, 2024
@obulat obulat removed the ⛔ status: blocked Blocked & therefore, not ready for work label Mar 25, 2024
@openverse-bot openverse-bot moved this from 📅 To Do to 📋 Backlog in Openverse Backlog Mar 25, 2024
@obulat
Copy link
Contributor Author

obulat commented Mar 25, 2024

Moving this to to-do as the blocking issues have been fixed (#3850 and #3811)

@obulat obulat moved this from 📋 Backlog to 📅 To Do in Openverse Backlog Mar 25, 2024
@obulat obulat added 🟨 priority: medium Not blocking but should be addressed soon and removed 🟧 priority: high Stalls work on the project or its dependents labels Mar 25, 2024
@obulat obulat self-assigned this Mar 28, 2024
@openverse-bot openverse-bot moved this from 📅 To Do to 🏗 In Progress in Openverse Backlog Apr 5, 2024
@openverse-bot openverse-bot moved this from 🏗 In Progress to ✅ Done in Openverse Backlog Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
3 participants