Skip to content

Commit

Permalink
send data as blob to avoid making sync xhr requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkanal committed Aug 26, 2022
1 parent b18e49e commit b4effd1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 7 additions & 1 deletion examples/opentelemetry-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const provider = new WebTracerProvider();
provider.addSpanProcessor(
new SimpleSpanProcessor(new OTLPTraceExporterProto())
);
// provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));
// provider.addSpanProcessor(
// new SimpleSpanProcessor(
// new OTLPTraceExporter({
// url: "https://api.honeycomb.io",
// })
// )
// );

provider.register({
contextManager: new ZoneContextManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class OTLPExporterBrowserBase<
ExportItem,
ServiceRequest
> {
protected _headers: Record<string, string>;
public _headers: Record<string, string>;
private _useXHR: boolean = false;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function sendWithBeacon(
* @param onError
*/
export function sendWithXhr(
body: string | ArrayBuffer,
body: string | Blob,
url: string,
headers: Record<string, string>,
exporterTimeout: number,
Expand All @@ -67,7 +67,7 @@ export function sendWithXhr(
}, exporterTimeout);

const xhr = new XMLHttpRequest();
xhr.open('POST', url, false);
xhr.open('POST', url);

const defaultHeaders = {
'Accept': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ export function send<ExportItem, ServiceRequest>(
const body = exportRequestType.encode(message).finish();
if (body) {
sendWithXhr(
body,
new Blob([body], { type: 'application/x-protobuf'}),
collector.url,
// probably need to add headers?
{'Content-Type': 'application/x-protobuf'},
{'Content-Type': 'application/x-protobuf', ...collector._headers},
collector.timeoutMillis,
onSuccess,
onError
Expand Down

0 comments on commit b4effd1

Please sign in to comment.