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

Web browser span exporters should support navigator.sendBeacon #464

Closed
danwild opened this issue Oct 29, 2019 · 5 comments
Closed

Web browser span exporters should support navigator.sendBeacon #464

danwild opened this issue Oct 29, 2019 · 5 comments

Comments

@danwild
Copy link

danwild commented Oct 29, 2019

When a web browser compatible span exporter package is developed, it will need a way to reliably ensure any open spans are ended and exported when user navigates away from the browser window (for context - I've just been experimenting crudely with wiring up zipkin exporter to jaeger via HTTP POST and realised this is a problem).

Historically, web developers have used work-arounds leveraging the unload / beforeunload window events, however these are clearly smelly and unreliable.

I would be nicer if such a package could play nicely with the navigator.sendBeacon method.

By design, navigator.sendBeacon must execute the async request itself, so to support this - we probably just need exporter to expose methods for:

  • returning endpoint used for span reporting
  • returning spans payload (formatted ready to send to the endpoint)

e.g.

window.addEventListener("unload", logData, false);

function logData() {
  const serviceUrl = myExporter.getServiceUrl();
  const payload = myExporter.getPayload();
  navigator.sendBeacon(serviceUrl, payload);
}
@danwild danwild changed the title Web browser span exporters should support navigator.sendBeacon Web browser span exporters should support navigator.sendBeacon Oct 29, 2019
@danwild
Copy link
Author

danwild commented Oct 29, 2019

Worth noting that sendBeacon has limitations on transmission format due to security issues, e.g. application/json which might make things a little tricky.

@obecny
Copy link
Member

obecny commented Oct 30, 2019

@danwild thx for pointing this out. There is not yet dedicated exporter for a web browser - this is going to be implemented in near future.

@draffensperger
Copy link
Contributor

Yeah, I think the main challenge here is how to encode the spans in the beacon well, but I think this is a good idea!

@bradfrosty
Copy link
Contributor

I believe this issue can be closed, @openetelemetry/exporter-collector has been implemented and supports navigator.sendBeacon().

@obecny
Copy link
Member

obecny commented Dec 4, 2020

done already

@obecny obecny closed this as completed Dec 4, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this issue Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants