-
Notifications
You must be signed in to change notification settings - Fork 1k
XMLHttpRequest #595
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
Merged
Merged
XMLHttpRequest #595
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
8fce91a
feat(xml-http-request): new plugin for auto instrumentation for xml-h…
obecny 0875f3f
chore: new example for xml-http-request and updated examples structur…
obecny f1c6013
chore: updating readme
obecny 6038bcc
chore: linting
obecny ac68ab9
chore: fixing origin for tests
obecny 87dcdc6
chore: linting
obecny 6e10df7
chore: updating to use b3 format from core
obecny e91d8f9
chore: updates after reviews
obecny 8e01e96
chore: wrong function call
obecny 898c190
chore: updating attribute names
obecny 54d0ba0
chore: linting
obecny 9f2c563
chore: adding preflight requests, fixing few other issues
obecny 8a17c2a
chore: adding image to examples, updating readme
obecny db00221
chore: forcing async to be true, but propagate rest params
obecny ef66398
chore: fixing type for open and send function
obecny 7d884db
chore: fixing format for headers
obecny 3e39b1a
chore: reviews
obecny bcc1204
chore: decrement task count when span exists
obecny c9163e5
chore: changes after review
obecny f73aacb
chore: adding weakmap for keeping information connected with xhr
obecny 88e122a
chore: renaming config param
obecny c3dac11
chore: not needed cast
obecny 524da7a
chore: updating title
obecny 50e151e
chore: refactored xhr, removed tracing dependency, few other issues f…
obecny 6c143e7
chore: reviews
obecny 3d7b32e
chore: refactored for collecting timing resources
obecny 91bad5d
chore: merge branch 'master' into xml-http-request
obecny 5aa23ca
chore: fixes after merging
obecny ab9795a
chore: reviews
obecny 4d4e65f
chore: reviews
obecny ca96cb1
Merge branch 'master' into xml-http-request
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Web Tracer Example</title> | ||
| <base href="/"> | ||
|
|
||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| </head> | ||
|
|
||
| <body> | ||
| Example of using Web Tracer with XMLHttpRequest plugin with console exporter and collector exporter | ||
| <script type="text/javascript" src="xml-http-request.js"></script> | ||
| <br/> | ||
| <button id="button1">Test</button> | ||
|
|
||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or 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,59 @@ | ||
| import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; | ||
mayurkale22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { WebTracer } from '@opentelemetry/web'; | ||
| import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request'; | ||
| import { ZoneScopeManager } from '@opentelemetry/scope-zone'; | ||
| import { CollectorExporter } from '@opentelemetry/exporter-collector'; | ||
| import { B3Format } from '@opentelemetry/core'; | ||
|
|
||
| const webTracerWithZone = new WebTracer({ | ||
| httpTextFormat: new B3Format(), | ||
| scopeManager: new ZoneScopeManager(), | ||
| plugins: [ | ||
| new XMLHttpRequestPlugin({ | ||
| ignoreUrls: ['http://localhost:8090/sockjs-node/info'], | ||
| propagateTraceHeaderCorsUrls: [ | ||
| 'http://localhost:8090' | ||
obecny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
obecny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ] | ||
| }) | ||
| ] | ||
| }); | ||
|
|
||
| webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); | ||
| webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); | ||
|
|
||
| // example of keeping track of scope between async operations | ||
| const prepareClickEvent = () => { | ||
| const url1 = 'https://httpbin.org/get'; | ||
|
|
||
| const element = document.getElementById('button1'); | ||
|
|
||
| const onClick = () => { | ||
| for (let i = 0, j = 5; i < j; i++) { | ||
| const span1 = webTracerWithZone.startSpan(`files-series-info-${i}`, { | ||
| parent: webTracerWithZone.getCurrentSpan() | ||
|
Contributor
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 believe if there is no current span, this span will just be a root span, which is the correct behavior. I think my comment about having a nice root span for XHRs is more like a future feature and not so much an issue with this code. |
||
| }); | ||
| webTracerWithZone.withSpan(span1, () => { | ||
| getData(url1).then((data) => { | ||
| webTracerWithZone.getCurrentSpan().addEvent('fetching-span1-completed'); | ||
| span1.end(); | ||
| }); | ||
| }); | ||
| } | ||
| }; | ||
| element.addEventListener('click', onClick); | ||
| }; | ||
|
|
||
| const getData = (url) => { | ||
| return new Promise(async (resolve, reject) => { | ||
| const req = new XMLHttpRequest(); | ||
| req.open('GET', url, true); | ||
| req.setRequestHeader('Content-Type', 'application/json'); | ||
| req.setRequestHeader('Accept', 'application/json'); | ||
| req.send(); | ||
| req.onload = function () { | ||
| resolve(); | ||
| }; | ||
| }); | ||
| }; | ||
|
|
||
| window.addEventListener('load', prepareClickEvent); | ||
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| /*! | ||
| * Copyright 2019, 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Check if {@param url} matches {@param urlToMatch} | ||
| * @param url | ||
| * @param urlToMatch | ||
| */ | ||
| export function urlMatches(url: string, urlToMatch: string | RegExp): boolean { | ||
| if (typeof urlToMatch === 'string') { | ||
| return url === urlToMatch; | ||
| } else { | ||
| return !!url.match(urlToMatch); | ||
| } | ||
| } | ||
| /** | ||
| * Check if {@param url} should be ignored when comparing against {@param ignoredUrls} | ||
| * @param url | ||
| * @param ignoredUrls | ||
| */ | ||
| export function isUrlIgnored( | ||
| url: string, | ||
| ignoredUrls?: Array<string | RegExp> | ||
| ): boolean { | ||
| if (!ignoredUrls) { | ||
| return false; | ||
| } | ||
|
|
||
| for (const ignoreUrl of ignoredUrls) { | ||
| if (urlMatches(url, ignoreUrl)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } |
This file contains hidden or 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,30 @@ | ||
| /*! | ||
| * Copyright 2019, 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 { ShimWrapped } from '../common/types'; | ||
|
|
||
| /** | ||
| * Checks if certain function has been already wrapped | ||
| * @param func | ||
| */ | ||
| export function isWrapped(func: any) { | ||
| return ( | ||
| typeof func === 'function' && | ||
| typeof (func as ShimWrapped).__original === 'function' && | ||
| typeof (func as ShimWrapped).__unwrap === 'function' && | ||
| (func as ShimWrapped).__wrapped === true | ||
| ); | ||
| } |
This file contains hidden or 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,75 @@ | ||
| /** | ||
| * Copyright 2019, 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 * as assert from 'assert'; | ||
|
|
||
| import { isUrlIgnored } from '../../src'; | ||
|
|
||
| const urlIgnored = 'url should be ignored'; | ||
| const urlNotIgnored = 'url should NOT be ignored'; | ||
|
|
||
| const urlToTest = 'http://myaddress.com/somepath'; | ||
|
|
||
| describe('BasePlugin - Utils', () => { | ||
| describe('isUrlIgnored', () => { | ||
| describe('when ignored urls are undefined', () => { | ||
| it('should return false', () => { | ||
| assert.strictEqual(isUrlIgnored(urlToTest), false, urlNotIgnored); | ||
| }); | ||
| }); | ||
| describe('when ignored urls are empty', () => { | ||
| it('should return false', () => { | ||
| assert.strictEqual(isUrlIgnored(urlToTest, []), false, urlNotIgnored); | ||
| }); | ||
| }); | ||
| describe('when ignored urls is the same as url', () => { | ||
| it('should return true', () => { | ||
| assert.strictEqual( | ||
| isUrlIgnored(urlToTest, ['http://myaddress.com/somepath']), | ||
| true, | ||
| urlIgnored | ||
| ); | ||
| }); | ||
| }); | ||
| describe('when url is part of ignored urls', () => { | ||
| it('should return false', () => { | ||
| assert.strictEqual( | ||
| isUrlIgnored(urlToTest, ['http://myaddress.com/some']), | ||
| false, | ||
| urlNotIgnored | ||
| ); | ||
| }); | ||
| }); | ||
| describe('when ignored urls is part of url - REGEXP', () => { | ||
| it('should return true', () => { | ||
| assert.strictEqual( | ||
| isUrlIgnored(urlToTest, [/.+?myaddress\.com/]), | ||
| true, | ||
| urlIgnored | ||
| ); | ||
| }); | ||
| }); | ||
| describe('when url is part of ignored urls - REGEXP', () => { | ||
| it('should return false', () => { | ||
| assert.strictEqual( | ||
| isUrlIgnored(urlToTest, [/http:\/\/myaddress\.com\/somepath2/]), | ||
| false, | ||
| urlNotIgnored | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.