-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(xml-http-request): new plugin for auto instrumentation for xml-http-request * chore: new example for xml-http-request and updated examples structure for web * chore: updating readme * chore: linting * chore: fixing origin for tests * chore: linting * chore: updating to use b3 format from core * chore: updates after reviews * chore: wrong function call * chore: updating attribute names * chore: linting * chore: adding preflight requests, fixing few other issues * chore: adding image to examples, updating readme * chore: forcing async to be true, but propagate rest params * chore: fixing type for open and send function * chore: fixing format for headers * chore: reviews * chore: decrement task count when span exists * chore: changes after review * chore: adding weakmap for keeping information connected with xhr * chore: renaming config param * chore: not needed cast * chore: updating title * chore: refactored xhr, removed tracing dependency, few other issues fixed * chore: reviews * chore: refactored for collecting timing resources * chore: fixes after merging * chore: reviews * chore: reviews Co-authored-by: Mayur Kale <[email protected]>
- Loading branch information
1 parent
e8db33a
commit bc583b8
Showing
42 changed files
with
2,701 additions
and
74 deletions.
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
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,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>XMLHttpRequest Plugin 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 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,61 @@ | ||
'use strict'; | ||
|
||
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; | ||
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: [/localhost:8090\/sockjs-node/], | ||
propagateTraceHeaderCorsUrls: [ | ||
'https://httpbin.org/get' | ||
] | ||
}) | ||
] | ||
}); | ||
|
||
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() | ||
}); | ||
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 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
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
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 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 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.