-
Notifications
You must be signed in to change notification settings - Fork 821
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
fix: refactoring and solves #2321 #2380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,12 @@ export abstract class CollectorExporterBrowserBase< | |
ExportItem, | ||
ServiceRequest | ||
> { | ||
private DEFAULT_HEADERS = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
private DEFAULT_BLOB_TYPE = { type: 'application/json' }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imho it should not be a part of CollectorExporterBrowserBase.ts as it is only used if beacon is used -> move to util There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the logic deciding if beacon is used , is a decision that |
||
|
||
protected _headers: Record<string, string>; | ||
private _useXHR: boolean = false; | ||
|
||
|
@@ -43,16 +49,20 @@ export abstract class CollectorExporterBrowserBase< | |
super(config); | ||
this._useXHR = | ||
!!config.headers || typeof navigator.sendBeacon !== 'function'; | ||
|
||
if (this._useXHR) { | ||
this._headers = Object.assign( | ||
{}, | ||
parseHeaders(config.headers), | ||
baggageUtils.parseKeyPairsIntoRecord( | ||
this._headers = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to have 2 util functions
Currently the logic will be scattered between util and exporter, where exporter should not contain anymore logic then it is necessary and those functions will be straightforward and easy to understand. If someone want to change it you will change util class not the exporter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually i think that the correct place would be to put the utility functions like the ones you mention here under What do you think ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or a better one, what do you think ? rename the file Then introduce a util.ts under
Then send module and util module can be imported to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @obecny a more consistent solution is given by @MSNev in context of blob and sendWithBeacon here: So can i move the default header for xhr inside the send method of to send method here: it should then look something like this:
i would then close this PR and open a new one in order to be in context of xhr only , given the blob context PR will be handled here: #2336 @obecny , @MSNev, what do you think for the above refactoring proposal for xhr ? |
||
...this.DEFAULT_HEADERS, | ||
...parseHeaders(config.headers), | ||
...baggageUtils.parseKeyPairsIntoRecord( | ||
getEnv().OTEL_EXPORTER_OTLP_HEADERS | ||
) | ||
); | ||
), | ||
}; | ||
} else { | ||
this._headers = {}; | ||
this._headers = { | ||
...this.DEFAULT_BLOB_TYPE, | ||
...parseHeaders({ type: config.blobType }), | ||
}; | ||
} | ||
} | ||
|
||
|
@@ -94,7 +104,7 @@ export abstract class CollectorExporterBrowserBase< | |
if (this._useXHR) { | ||
sendWithXhr(body, this.url, this._headers, _onSuccess, _onError); | ||
} else { | ||
sendWithBeacon(body, this.url, _onSuccess, _onError); | ||
sendWithBeacon(body, this.url, this._headers, _onSuccess, _onError); | ||
} | ||
}); | ||
this._sendingPromises.push(promise); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you think it's better to keep defaults on instance instead in utils ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct me if i am wrong.
Who owns the config ?
CollectorExporterBrowserBase
What are the methods
sendWithXhr
,sendWithBeacon
underopentelemetry-js/packages/opentelemetry-exporter-collector/src/platform/browser/util.ts ?