-
Notifications
You must be signed in to change notification settings - Fork 807
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: exporter collector TLS option #1063
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4c5c029
feat: exporter collector TLS option
mzahor 1f5db6d
refactor: move certs to tests folder
mzahor 0451261
Merge branch 'master' into feat/otlp-tls
mzahor 622ded7
refactor: code style
mzahor cc3c75a
Merge branch 'master' into feat/otlp-tls
mzahor b059956
doc: add TLS docs
mzahor 40567dc
Merge branch 'feat/otlp-tls' of github.com:mzahor/opentelemetry-js in…
mzahor 764a555
doc: add reference to TLS cert gen script
mzahor 9d1ae0b
refactor: use separate impl for node and browser
mzahor b2eae13
fix: unit tests
mzahor 182e6c7
style: fix codestyle
mzahor 61e4916
fix: compilation
mzahor 7a99848
doc: emphasize that TLS is Node-specific
mzahor 9c3158b
Merge branch 'master' into feat/otlp-tls
mzahor a2e7acf
fix: doc comment
mzahor 8db7d91
Merge branch 'feat/otlp-tls' of github.com:mzahor/opentelemetry-js in…
mzahor bae411c
Merge branch 'feat/otlp-tls' of github.com:mzahor/opentelemetry-js in…
mzahor f2b5bc1
Merge branch 'feat/otlp-tls' of github.com:mzahor/opentelemetry-js in…
mzahor 1deecaf
fix: exports
mzahor 1e31648
style: fix linting issues
mzahor 74eab02
refactor: remove weakmap
mzahor 231d228
Merge branch 'master' into feat/otlp-tls
mayurkale22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/opentelemetry-exporter-collector/src/platform/browser/CollectorExporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/*! | ||
* Copyright 2020, OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
CollectorExporterBase, | ||
CollectorExporterConfigBase, | ||
} from '../../CollectorExporterBase'; | ||
import { ReadableSpan } from '@opentelemetry/tracing'; | ||
import { toCollectorExportTraceServiceRequest } from '../../transform'; | ||
import * as collectorTypes from '../../types'; | ||
|
||
export interface CollectorExporterConfig extends CollectorExporterConfigBase {} | ||
|
||
/** | ||
* Collector Exporter for Web | ||
*/ | ||
export class CollectorExporter extends CollectorExporterBase< | ||
CollectorExporterConfig | ||
> { | ||
onInit(): void { | ||
window.addEventListener('unload', this.shutdown); | ||
} | ||
|
||
onShutdown(): void { | ||
window.removeEventListener('unload', this.shutdown); | ||
} | ||
|
||
sendSpans( | ||
spans: ReadableSpan[], | ||
onSuccess: () => void, | ||
onError: (error: collectorTypes.CollectorExporterError) => void | ||
) { | ||
const exportTraceServiceRequest = toCollectorExportTraceServiceRequest( | ||
spans, | ||
this | ||
); | ||
|
||
const body = JSON.stringify(exportTraceServiceRequest); | ||
|
||
if (typeof navigator.sendBeacon === 'function') { | ||
this._sendSpansWithBeacon(body, onSuccess, onError); | ||
} else { | ||
this._sendSpansWithXhr(body, onSuccess, onError); | ||
} | ||
} | ||
|
||
/** | ||
* send spans using browser navigator.sendBeacon | ||
* @param body | ||
* @param onSuccess | ||
* @param onError | ||
*/ | ||
private _sendSpansWithBeacon( | ||
body: string, | ||
onSuccess: () => void, | ||
onError: (error: collectorTypes.CollectorExporterError) => void | ||
) { | ||
if (navigator.sendBeacon(this.url, body)) { | ||
this.logger.debug('sendBeacon - can send', body); | ||
onSuccess(); | ||
} else { | ||
this.logger.error('sendBeacon - cannot send', body); | ||
onError({}); | ||
} | ||
} | ||
|
||
/** | ||
* function to send spans using browser XMLHttpRequest | ||
* used when navigator.sendBeacon is not available | ||
* @param body | ||
* @param onSuccess | ||
* @param onError | ||
*/ | ||
private _sendSpansWithXhr( | ||
body: string, | ||
onSuccess: () => void, | ||
onError: (error: collectorTypes.CollectorExporterError) => void | ||
) { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('POST', this.url); | ||
xhr.setRequestHeader(collectorTypes.OT_REQUEST_HEADER, '1'); | ||
xhr.setRequestHeader('Accept', 'application/json'); | ||
xhr.setRequestHeader('Content-Type', 'application/json'); | ||
xhr.send(body); | ||
|
||
xhr.onreadystatechange = () => { | ||
if (xhr.readyState === XMLHttpRequest.DONE) { | ||
if (xhr.status >= 200 && xhr.status <= 299) { | ||
this.logger.debug('xhr success', body); | ||
onSuccess(); | ||
} else { | ||
this.logger.error('body', body); | ||
this.logger.error('xhr error', xhr); | ||
onError({ | ||
code: xhr.status, | ||
message: xhr.responseText, | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
export * from './sendSpans'; | ||
export * from './CollectorExporter'; |
141 changes: 0 additions & 141 deletions
141
packages/opentelemetry-exporter-collector/src/platform/browser/sendSpans.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please mark this is for node only, not browser