-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,653 additions
and
43 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 |
---|---|---|
@@ -1,11 +1,83 @@ | ||
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; | ||
import { WebTracer } from '@opentelemetry/web'; | ||
import { DocumentLoad } from '@opentelemetry/plugin-document-load'; | ||
import { ZoneScopeManager } from '@opentelemetry/scope-zone'; | ||
|
||
const webTracer = new WebTracer({ | ||
plugins: [ | ||
new DocumentLoad() | ||
] | ||
}); | ||
|
||
webTracer.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); | ||
|
||
const webTracerWithZone = new WebTracer({ | ||
scopeManager: new ZoneScopeManager(), | ||
plugins: [ | ||
new DocumentLoad() | ||
] | ||
}); | ||
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); | ||
|
||
console.log('Current span is window', webTracerWithZone.getCurrentSpan() === window); | ||
|
||
// example of keeping track of scope between async operations | ||
const prepareClickEvent = () => { | ||
const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/package.json'; | ||
const url2 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/packages/opentelemetry-web/package.json'; | ||
|
||
const element = document.getElementById('button1'); | ||
let mainSpan = webTracerWithZone.startSpan('main-span'); | ||
webTracerWithZone.bind(element, mainSpan); | ||
|
||
const onClick = () => { | ||
const span1 = webTracerWithZone.startSpan(`files-series-info-1`, { | ||
parent: webTracerWithZone.getCurrentSpan() | ||
}); | ||
|
||
const span2 = webTracerWithZone.startSpan(`files-series-info-2`, { | ||
parent: webTracerWithZone.getCurrentSpan() | ||
}); | ||
|
||
webTracerWithZone.withSpan(span1, () => { | ||
getData(url1).then((data) => { | ||
console.log('current span is span1', webTracerWithZone.getCurrentSpan() === span1); | ||
console.log('info from package.json', data.description, data.version); | ||
webTracerWithZone.getCurrentSpan().addEvent('fetching-span1-completed'); | ||
span1.end(); | ||
}); | ||
}); | ||
|
||
webTracerWithZone.withSpan(span2, () => { | ||
getData(url2).then((data) => { | ||
setTimeout(() => { | ||
console.log('current span is span2', webTracerWithZone.getCurrentSpan() === span2); | ||
console.log('info from package.json', data.description, data.version); | ||
webTracerWithZone.getCurrentSpan().addEvent('fetching-span2-completed'); | ||
span2.end(); | ||
}, 100); | ||
}); | ||
}); | ||
}; | ||
element.addEventListener('click', onClick); | ||
}; | ||
|
||
const getData = (url) => { | ||
return new Promise(async (resolve, reject) => { | ||
const req = new XMLHttpRequest(); | ||
req.open('GET', url, true); | ||
req.send(); | ||
req.onload = function () { | ||
let json; | ||
try { | ||
json = JSON.parse(req.responseText); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
resolve(json); | ||
}; | ||
}); | ||
}; | ||
|
||
window.addEventListener('load', () => { | ||
prepareClickEvent(); | ||
}); |
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
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
Oops, something went wrong.