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

feat: use Blob in sendBeacon to add application/json type #2336

Merged
merged 14 commits into from Aug 10, 2021
Expand Up @@ -28,7 +28,7 @@ export function sendWithBeacon(
onSuccess: () => void,
onError: (error: collectorTypes.CollectorExporterError) => void
) {
if (navigator.sendBeacon(url, body)) {
if (navigator.sendBeacon(url, new Blob([body], { type: "application/json" }))) {
vmarchaud marked this conversation as resolved.
Show resolved Hide resolved
diag.debug('sendBeacon - can send', body);
onSuccess();
} else {
Expand Down
Expand Up @@ -93,10 +93,11 @@ describe('CollectorMetricExporter - web', () => {
it('should successfully send metrics using sendBeacon', done => {
collectorExporter.export(metrics, () => {});

setTimeout(() => {
setTimeout(async () => {
const args = stubBeacon.args[0];
const url = args[0];
const body = args[1];
const blob:Blob = args[1];
dyladan marked this conversation as resolved.
Show resolved Hide resolved
const body = await blob.text();
const json = JSON.parse(
body
) as collectorTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest;
Expand Down
Expand Up @@ -69,10 +69,11 @@ describe('CollectorTraceExporter - web', () => {
it('should successfully send the spans using sendBeacon', done => {
collectorTraceExporter.export(spans, () => {});

setTimeout(() => {
setTimeout(async () => {
const args = stubBeacon.args[0];
const url = args[0];
const body = args[1];
const blob:Blob = args[1];
const body = await blob.text();
const json = JSON.parse(
body
) as collectorTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest;
Expand Down