chore: upgrading to api ver. 0.20.0 (#2225)
* chore: upgrading to api ver. 0.20.0
This commit is contained in:
parent
eb9353a9cb
commit
ac81e17c68
|
@ -37,7 +37,7 @@ exporter.shutdown();
|
|||
function doWork(parent) {
|
||||
// Start another span. In this example, the main method already started a
|
||||
// span, so that'll be the parent span, and this will be a child span.
|
||||
const ctx = opentelemetry.setSpan(opentelemetry.context.active(), parent);
|
||||
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), parent);
|
||||
const span = tracer.startSpan('doWork', undefined, ctx);
|
||||
|
||||
// simulate some random work.
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/exporter-jaeger": "0.19.0",
|
||||
"@opentelemetry/tracing": "0.19.0"
|
||||
},
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
"@opentelemetry/exporter-collector": "0.19.0",
|
||||
"@opentelemetry/exporter-collector-grpc": "0.19.0",
|
||||
|
|
|
@ -42,7 +42,7 @@ setTimeout(() => {
|
|||
function doWork(parent) {
|
||||
// Start another span. In this example, the main method already started a
|
||||
// span, so that'll be the parent span, and this will be a child span.
|
||||
const ctx = opentelemetry.setSpan(opentelemetry.context.active(), parent);
|
||||
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), parent);
|
||||
const span = tracer.startSpan('doWork', undefined, ctx);
|
||||
|
||||
// simulate some random work.
|
||||
|
|
|
@ -15,8 +15,8 @@ function main() {
|
|||
// the span, which is created to track work that happens outside of the
|
||||
// request lifecycle entirely.
|
||||
const span = tracer.startSpan('client.js:main()');
|
||||
api.context.with(api.setSpan(api.context.active(), span), () => {
|
||||
console.log('Client traceId ', span.context().traceId);
|
||||
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
|
||||
console.log('Client traceId ', span.spanContext().traceId);
|
||||
const client = new services.GreeterClient(
|
||||
`localhost:${PORT}`,
|
||||
grpc.credentials.createInsecure(),
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.2.12",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/exporter-jaeger": "0.19.0",
|
||||
"@opentelemetry/exporter-zipkin": "0.19.0",
|
||||
"@opentelemetry/instrumentation": "0.19.0",
|
||||
|
|
|
@ -22,9 +22,9 @@ function startServer() {
|
|||
}
|
||||
|
||||
function sayHello(call, callback) {
|
||||
const currentSpan = api.getSpan(api.context.active());
|
||||
const currentSpan = api.trace.getSpan(api.context.active());
|
||||
// display traceid in the terminal
|
||||
console.log(`traceid: ${currentSpan.context().traceId}`);
|
||||
console.log(`traceid: ${currentSpan.spanContext().traceId}`);
|
||||
const span = tracer.startSpan('server.js:sayHello()', {
|
||||
kind: 1, // server
|
||||
attributes: { key: 'value' },
|
||||
|
|
|
@ -15,8 +15,8 @@ function main() {
|
|||
// the span, which is created to track work that happens outside of the
|
||||
// request lifecycle entirely.
|
||||
const span = tracer.startSpan('client.js:main()');
|
||||
api.context.with(api.setSpan(api.context.active(), span), () => {
|
||||
console.log('Client traceId ', span.context().traceId);
|
||||
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
|
||||
console.log('Client traceId ', span.spanContext().traceId);
|
||||
const client = new services.GreeterClient(
|
||||
`localhost:${PORT}`,
|
||||
grpc.credentials.createInsecure(),
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/exporter-jaeger": "0.19.0",
|
||||
"@opentelemetry/exporter-zipkin": "0.19.0",
|
||||
"@opentelemetry/instrumentation": "0.19.0",
|
||||
|
|
|
@ -21,9 +21,9 @@ function startServer() {
|
|||
}
|
||||
|
||||
function sayHello(call, callback) {
|
||||
const currentSpan = api.getSpan(api.context.active());
|
||||
const currentSpan = api.trace.getSpan(api.context.active());
|
||||
// display traceid in the terminal
|
||||
console.log(`traceid: ${currentSpan.context().traceId}`);
|
||||
console.log(`traceid: ${currentSpan.spanContext().traceId}`);
|
||||
const span = tracer.startSpan('server.js:sayHello()', {
|
||||
parent: currentSpan,
|
||||
kind: 1, // server
|
||||
|
|
|
@ -11,7 +11,7 @@ function makeRequest() {
|
|||
// the span, which is created to track work that happens outside of the
|
||||
// request lifecycle entirely.
|
||||
const span = tracer.startSpan('makeRequest');
|
||||
api.context.with(api.setSpan(api.context.active(), span), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
|
||||
http.get({
|
||||
host: 'localhost',
|
||||
port: 8080,
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/exporter-jaeger": "0.19.0",
|
||||
"@opentelemetry/exporter-zipkin": "0.19.0",
|
||||
"@opentelemetry/instrumentation": "0.19.0",
|
||||
|
|
|
@ -20,9 +20,9 @@ function startServer(port) {
|
|||
|
||||
/** A function which handles requests and send response. */
|
||||
function handleRequest(request, response) {
|
||||
const currentSpan = api.getSpan(api.context.active());
|
||||
const currentSpan = api.trace.getSpan(api.context.active());
|
||||
// display traceid in the terminal
|
||||
console.log(`traceid: ${currentSpan.context().traceId}`);
|
||||
console.log(`traceid: ${currentSpan.spanContext().traceId}`);
|
||||
const span = tracer.startSpan('handleRequest', {
|
||||
kind: 1, // server
|
||||
attributes: { key: 'value' },
|
||||
|
|
|
@ -11,7 +11,7 @@ function makeRequest() {
|
|||
// the span, which is created to track work that happens outside of the
|
||||
// request lifecycle entirely.
|
||||
const span = tracer.startSpan('makeRequest');
|
||||
api.context.with(api.setSpan(api.context.active(), span), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
|
||||
https.get({
|
||||
host: 'localhost',
|
||||
port: 443,
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/exporter-jaeger": "0.19.0",
|
||||
"@opentelemetry/exporter-zipkin": "0.19.0",
|
||||
"@opentelemetry/instrumentation": "0.19.0",
|
||||
|
|
|
@ -25,9 +25,9 @@ function startServer(port) {
|
|||
|
||||
/** A function which handles requests and send response. */
|
||||
function handleRequest(request, response) {
|
||||
const currentSpan = api.getSpan(api.context.active());
|
||||
const currentSpan = api.trace.getSpan(api.context.active());
|
||||
// display traceid in the terminal
|
||||
console.log(`traceid: ${currentSpan.context().traceId}`);
|
||||
console.log(`traceid: ${currentSpan.spanContext().traceId}`);
|
||||
const span = tracer.startSpan('handleRequest', {
|
||||
kind: 1, // server
|
||||
attributes: { key: 'value' },
|
||||
|
|
|
@ -37,7 +37,7 @@ async function handleRequest(req, res) {
|
|||
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.write(
|
||||
JSON.stringify({ status: 'OK', traceId: span.context().toTraceId() }),
|
||||
JSON.stringify({ status: 'OK', traceId: span.spanContext().toTraceId() }),
|
||||
);
|
||||
|
||||
res.end();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
// for debugging
|
||||
// import { context, getSpan, setSpan } from '../../../../packages/opentelemetry-api/src';
|
||||
import { context, getSpan, setSpan } from '@opentelemetry/api';
|
||||
import { context, trace } from '@opentelemetry/api';
|
||||
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
|
||||
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
|
||||
import { WebTracerProvider } from '@opentelemetry/web';
|
||||
|
@ -49,17 +47,17 @@ const prepareClickEvent = () => {
|
|||
|
||||
const onClick = () => {
|
||||
const singleSpan = webTracerWithZone.startSpan(`files-series-info`);
|
||||
context.with(setSpan(context.active(), singleSpan), () => {
|
||||
context.with(trace.setSpan(context.active(), singleSpan), () => {
|
||||
getData(url).then((_data) => {
|
||||
getSpan(context.active()).addEvent('fetching-single-span-completed');
|
||||
trace.getSpan(context.active()).addEvent('fetching-single-span-completed');
|
||||
singleSpan.end();
|
||||
});
|
||||
});
|
||||
for (let i = 0, j = 5; i < j; i += 1) {
|
||||
const span = webTracerWithZone.startSpan(`files-series-info-${i}`);
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
getData(url).then((_data) => {
|
||||
getSpan(context.active()).addEvent(`fetching-span-${i}-completed`);
|
||||
trace.getSpan(context.active()).addEvent(`fetching-span-${i}-completed`);
|
||||
span.end();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { context, getSpan, setSpan } from '@opentelemetry/api';
|
||||
import { context, trace } from '@opentelemetry/api';
|
||||
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
|
||||
import { WebTracerProvider } from '@opentelemetry/web';
|
||||
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
|
||||
|
@ -53,12 +53,12 @@ const prepareClickEvent = () => {
|
|||
const onClick = () => {
|
||||
for (let i = 0, j = 5; i < j; i += 1) {
|
||||
const span1 = webTracerWithZone.startSpan(`files-series-info-${i}`);
|
||||
context.with(setSpan(context.active(), span1), () => {
|
||||
context.with(trace.setSpan(context.active(), span1), () => {
|
||||
getData(url1).then((_data) => {
|
||||
getSpan(context.active()).addEvent('fetching-span1-completed');
|
||||
trace.getSpan(context.active()).addEvent('fetching-span1-completed');
|
||||
span1.end();
|
||||
}, ()=> {
|
||||
getSpan(context.active()).addEvent('fetching-error');
|
||||
trace.getSpan(context.active()).addEvent('fetching-error');
|
||||
span1.end();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"webpack-merge": "^4.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/context-zone": "0.19.0",
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
"@opentelemetry/exporter-collector": "0.19.0",
|
||||
|
|
|
@ -8,6 +8,7 @@ const common = {
|
|||
mode: 'development',
|
||||
entry: {
|
||||
metrics: 'examples/metrics/index.js',
|
||||
test: 'examples/test/test.ts',
|
||||
fetch: 'examples/fetch/index.js',
|
||||
'xml-http-request': 'examples/xml-http-request/index.js',
|
||||
zipkin: 'examples/zipkin/index.js',
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
"express": "4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const axios = require("axios");
|
||||
const { HttpTraceContextPropagator } = require("@opentelemetry/core");
|
||||
const { BasicTracerProvider } = require("@opentelemetry/tracing");
|
||||
const { context, propagation, setSpan, trace, ROOT_CONTEXT } = require("@opentelemetry/api");
|
||||
const { context, propagation, trace, ROOT_CONTEXT } = require("@opentelemetry/api");
|
||||
const {
|
||||
AsyncHooksContextManager,
|
||||
} = require("@opentelemetry/context-async-hooks");
|
||||
|
@ -36,7 +36,7 @@ app.post("/verify-tracecontext", (req, res) => {
|
|||
req.body.map((action) => {
|
||||
const span = tracer.startSpan("propagate-w3c");
|
||||
let promise;
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
const headers = {};
|
||||
propagation.inject(context.active(), headers);
|
||||
promise = axios
|
||||
|
|
|
@ -53,10 +53,10 @@
|
|||
"access": "public"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/webpack-env": "1.16.0",
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/shimmer": "1.0.1",
|
||||
|
@ -53,6 +53,6 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ npm install --save @opentelemetry/context-zone-peer-dep
|
|||
## Usage
|
||||
|
||||
```js
|
||||
import { context, getSpan, setSpan } from '@opentelemetry/api';
|
||||
import { context, trace } from '@opentelemetry/api';
|
||||
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
|
||||
import { WebTracerProvider } from '@opentelemetry/web';
|
||||
import { ZoneContextManager } from '@opentelemetry/context-zone-peer-dep';
|
||||
|
@ -35,21 +35,21 @@ providerWithZone.register({
|
|||
// Example how the ZoneContextManager keeps the reference to the correct context during async operations
|
||||
const webTracerWithZone = providerWithZone.getTracer('default');
|
||||
const span1 = webTracerWithZone.startSpan('foo1');
|
||||
context.with(setSpan(context.active(), span1, () => {
|
||||
console.log('Current span is span1', getSpan(context.active()) === span1);
|
||||
context.with(trace.setSpan(context.active(), span1, () => {
|
||||
console.log('Current span is span1', trace.getSpan(context.active()) === span1);
|
||||
setTimeout(() => {
|
||||
const span2 = webTracerWithZone.startSpan('foo2');
|
||||
console.log('Current span is span1', getSpan(context.active()) === span1);
|
||||
context.with(setSpan(context.active(), span2, () => {
|
||||
console.log('Current span is span2', getSpan(context.active()) === span2);
|
||||
console.log('Current span is span1', trace.getSpan(context.active()) === span1);
|
||||
context.with(trace.setSpan(context.active(), span2, () => {
|
||||
console.log('Current span is span2', trace.getSpan(context.active()) === span2);
|
||||
setTimeout(() => {
|
||||
console.log('Current span is span2', getSpan(context.active()) === span2);
|
||||
console.log('Current span is span2', trace.getSpan(context.active()) === span2);
|
||||
}, 500);
|
||||
});
|
||||
// there is a timeout which still keeps span2 active
|
||||
console.log('Current span is span2', getSpan(context.active()) === span2);
|
||||
console.log('Current span is span2', trace.getSpan(context.active()) === span2);
|
||||
}, 500);
|
||||
console.log('Current span is span1', getSpan(context.active()) === span1);
|
||||
console.log('Current span is span1', trace.getSpan(context.active()) === span1);
|
||||
});
|
||||
|
||||
```
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -74,7 +74,7 @@
|
|||
"zone.js": "0.11.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"zone.js": "^0.10.2 || ^0.11.0"
|
||||
},
|
||||
"sideEffects": false
|
||||
|
|
|
@ -18,7 +18,7 @@ npm install --save @opentelemetry/context-zone
|
|||
## Usage
|
||||
|
||||
```js
|
||||
import { context, getSpan, setSpan } from '@opentelemetry/api';
|
||||
import { context, trace } from '@opentelemetry/api';
|
||||
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
|
||||
import { WebTracerProvider } from '@opentelemetry/web';
|
||||
import { ZoneContextManager } from '@opentelemetry/context-zone';
|
||||
|
@ -33,21 +33,21 @@ provider.register({
|
|||
const webTracerWithZone = providerWithZone.getTracer('default');
|
||||
const span1 = webTracerWithZone.startSpan('foo1');
|
||||
|
||||
context.with(setSpan(context.active(), span1), () => {
|
||||
console.log('Current span is span1', getSpan(context.active()) === span1);
|
||||
context.with(trace.setSpan(context.active(), span1), () => {
|
||||
console.log('Current span is span1', trace.getSpan(context.active()) === span1);
|
||||
setTimeout(() => {
|
||||
const span2 = webTracerWithZone.startSpan('foo2');
|
||||
console.log('Current span is span1', getSpan(context.active()) === span1);
|
||||
context.with(setSpan(context.active(), span2), () => {
|
||||
console.log('Current span is span2', getSpan(context.active()) === span2);
|
||||
console.log('Current span is span1', trace.getSpan(context.active()) === span1);
|
||||
context.with(trace.setSpan(context.active(), span2), () => {
|
||||
console.log('Current span is span2', trace.getSpan(context.active()) === span2);
|
||||
setTimeout(() => {
|
||||
console.log('Current span is span2', getSpan(context.active()) === span2);
|
||||
console.log('Current span is span2', trace.getSpan(context.active()) === span2);
|
||||
}, 500);
|
||||
});
|
||||
// there is a timeout which still keeps span2 active
|
||||
console.log('Current span is span2', getSpan(context.active()) === span2);
|
||||
console.log('Current span is span2', trace.getSpan(context.active()) === span2);
|
||||
}, 500);
|
||||
console.log('Current span is span1', getSpan(context.active()) === span1);
|
||||
console.log('Current span is span1', trace.getSpan(context.active()) === span1);
|
||||
});
|
||||
|
||||
```
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/semver": "7.3.5",
|
||||
|
@ -80,7 +80,7 @@
|
|||
"webpack": "4.46.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"semver": "^7.1.3",
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
import {
|
||||
BaggageEntry,
|
||||
Context,
|
||||
createBaggage,
|
||||
getBaggage,
|
||||
setBaggage,
|
||||
propagation,
|
||||
TextMapGetter,
|
||||
TextMapPropagator,
|
||||
TextMapSetter
|
||||
TextMapSetter,
|
||||
} from '@opentelemetry/api';
|
||||
|
||||
import { isTracingSuppressed } from '../../trace/suppress-tracing';
|
||||
import {
|
||||
BAGGAGE_HEADER,
|
||||
|
@ -45,7 +44,7 @@ import {
|
|||
*/
|
||||
export class HttpBaggagePropagator implements TextMapPropagator {
|
||||
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
|
||||
const baggage = getBaggage(context);
|
||||
const baggage = propagation.getBaggage(context);
|
||||
if (!baggage || isTracingSuppressed(context)) return;
|
||||
const keyPairs = getKeyPairs(baggage)
|
||||
.filter((pair: string) => {
|
||||
|
@ -79,7 +78,7 @@ export class HttpBaggagePropagator implements TextMapPropagator {
|
|||
if (Object.entries(baggage).length === 0) {
|
||||
return context;
|
||||
}
|
||||
return setBaggage(context, createBaggage(baggage));
|
||||
return propagation.setBaggage(context, propagation.createBaggage(baggage));
|
||||
}
|
||||
|
||||
fields(): string[] {
|
||||
|
|
|
@ -16,13 +16,11 @@
|
|||
|
||||
import {
|
||||
Context,
|
||||
getSpanContext,
|
||||
isSpanContextValid,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
TextMapGetter,
|
||||
TextMapPropagator,
|
||||
TextMapSetter,
|
||||
TextMapSetter, trace,
|
||||
TraceFlags,
|
||||
} from '@opentelemetry/api';
|
||||
import { isTracingSuppressed } from './suppress-tracing';
|
||||
|
@ -74,7 +72,7 @@ export function parseTraceParent(traceParent: string): SpanContext | null {
|
|||
*/
|
||||
export class HttpTraceContextPropagator implements TextMapPropagator {
|
||||
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
|
||||
const spanContext = getSpanContext(context);
|
||||
const spanContext = trace.getSpanContext(context);
|
||||
if (
|
||||
!spanContext ||
|
||||
isTracingSuppressed(context) ||
|
||||
|
@ -119,7 +117,7 @@ export class HttpTraceContextPropagator implements TextMapPropagator {
|
|||
typeof state === 'string' ? state : undefined
|
||||
);
|
||||
}
|
||||
return setSpanContext(context, spanContext);
|
||||
return trace.setSpanContext(context, spanContext);
|
||||
}
|
||||
|
||||
fields(): string[] {
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
import {
|
||||
SpanAttributes,
|
||||
Context,
|
||||
getSpanContext,
|
||||
isSpanContextValid,
|
||||
Link,
|
||||
Sampler,
|
||||
SamplingResult,
|
||||
SpanKind,
|
||||
TraceFlags,
|
||||
TraceFlags, trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { globalErrorHandler } from '../../common/global-error-handler';
|
||||
import { AlwaysOffSampler } from './AlwaysOffSampler';
|
||||
|
@ -68,7 +67,7 @@ export class ParentBasedSampler implements Sampler {
|
|||
attributes: SpanAttributes,
|
||||
links: Link[]
|
||||
): SamplingResult {
|
||||
const parentContext = getSpanContext(context);
|
||||
const parentContext = trace.getSpanContext(context);
|
||||
|
||||
if (!parentContext || !isSpanContextValid(parentContext)) {
|
||||
return this._root.shouldSample(
|
||||
|
|
|
@ -17,11 +17,9 @@
|
|||
import {
|
||||
Baggage,
|
||||
BaggageEntry,
|
||||
createBaggage,
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getBaggage,
|
||||
setBaggage,
|
||||
propagation,
|
||||
} from '@opentelemetry/api';
|
||||
import { ROOT_CONTEXT } from '@opentelemetry/api';
|
||||
import * as assert from 'assert';
|
||||
|
@ -39,14 +37,14 @@ describe('HttpBaggagePropagator', () => {
|
|||
|
||||
describe('.inject()', () => {
|
||||
it('should set baggage header', () => {
|
||||
const baggage = createBaggage({
|
||||
const baggage = propagation.createBaggage({
|
||||
key1: { value: 'd4cda95b652f4a1592b449d5929fda1b' },
|
||||
key3: { value: 'c88815a7-0fa9-4d95-a1f1-cdccce3c5c2a' },
|
||||
'with/slash': { value: 'with spaces' },
|
||||
});
|
||||
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -57,13 +55,13 @@ describe('HttpBaggagePropagator', () => {
|
|||
});
|
||||
|
||||
it('should skip long key-value pairs', () => {
|
||||
const baggage = createBaggage({
|
||||
const baggage = propagation.createBaggage({
|
||||
key1: { value: 'd4cda95b' },
|
||||
key3: { value: 'c88815a7' },
|
||||
});
|
||||
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -78,13 +76,13 @@ describe('HttpBaggagePropagator', () => {
|
|||
const shortKey = Array(95).fill('k').join('');
|
||||
const value = Array(4000).fill('v').join('');
|
||||
|
||||
let baggage = createBaggage({
|
||||
let baggage = propagation.createBaggage({
|
||||
aa: { value: 'shortvalue' },
|
||||
[shortKey]: { value: value },
|
||||
});
|
||||
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -93,14 +91,14 @@ describe('HttpBaggagePropagator', () => {
|
|||
assert.ok(typeof header === 'string');
|
||||
assert.deepStrictEqual(header, `aa=shortvalue,${shortKey}=${value}`);
|
||||
|
||||
baggage = createBaggage({
|
||||
baggage = propagation.createBaggage({
|
||||
aa: { value: 'shortvalue' },
|
||||
[longKey]: { value: value },
|
||||
});
|
||||
|
||||
carrier = {};
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -115,14 +113,14 @@ describe('HttpBaggagePropagator', () => {
|
|||
const longKey1 = Array(49).fill('1').join('');
|
||||
const longValue = Array(4000).fill('v').join('');
|
||||
|
||||
let baggage = createBaggage({
|
||||
let baggage = propagation.createBaggage({
|
||||
[longKey0]: { value: longValue },
|
||||
[longKey1]: { value: longValue },
|
||||
aa: { value: Array(88).fill('v').join('') },
|
||||
});
|
||||
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -132,7 +130,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
assert.deepStrictEqual(header.length, 8192);
|
||||
assert.deepStrictEqual(header.split(',').length, 3);
|
||||
|
||||
baggage = createBaggage({
|
||||
baggage = propagation.createBaggage({
|
||||
[longKey0]: { value: longValue },
|
||||
[longKey1]: { value: longValue },
|
||||
aa: { value: Array(89).fill('v').join('') },
|
||||
|
@ -140,7 +138,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
|
||||
carrier = {};
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -160,10 +158,10 @@ describe('HttpBaggagePropagator', () => {
|
|||
entries[`${i}`] = { value: 'v' };
|
||||
});
|
||||
|
||||
const baggage = createBaggage(entries);
|
||||
const baggage = propagation.createBaggage(entries);
|
||||
|
||||
httpBaggagePropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -178,7 +176,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
it('should extract context of a sampled span from carrier', () => {
|
||||
carrier[BAGGAGE_HEADER] =
|
||||
'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm';
|
||||
const extractedBaggage = getBaggage(
|
||||
const extractedBaggage = propagation.getBaggage(
|
||||
httpBaggagePropagator.extract(
|
||||
ROOT_CONTEXT,
|
||||
carrier,
|
||||
|
@ -186,7 +184,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
)
|
||||
);
|
||||
|
||||
const expected = createBaggage({
|
||||
const expected = propagation.createBaggage({
|
||||
key1: { value: 'd4cda95b' },
|
||||
key3: { value: 'c88815a7' },
|
||||
keyn: { value: 'valn' },
|
||||
|
@ -205,7 +203,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
|
||||
it('returns undefined if header is missing', () => {
|
||||
assert.deepStrictEqual(
|
||||
getBaggage(
|
||||
propagation.getBaggage(
|
||||
httpBaggagePropagator.extract(
|
||||
ROOT_CONTEXT,
|
||||
carrier,
|
||||
|
@ -218,7 +216,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
|
||||
it('returns keys with their properties', () => {
|
||||
carrier[BAGGAGE_HEADER] = 'key1=d4cda95b,key3=c88815a7;prop1=value1';
|
||||
const bag = getBaggage(
|
||||
const bag = propagation.getBaggage(
|
||||
httpBaggagePropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -260,7 +258,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
},
|
||||
mixInvalidAndValidKeys: {
|
||||
header: 'key1==value,key2=value2',
|
||||
baggage: createBaggage({
|
||||
baggage: propagation.createBaggage({
|
||||
key2: {
|
||||
value: 'value2',
|
||||
},
|
||||
|
@ -270,7 +268,7 @@ describe('HttpBaggagePropagator', () => {
|
|||
Object.getOwnPropertyNames(testCases).forEach(testCase => {
|
||||
carrier[BAGGAGE_HEADER] = testCases[testCase].header;
|
||||
|
||||
const extractedSpanContext = getBaggage(
|
||||
const extractedSpanContext = propagation.getBaggage(
|
||||
httpBaggagePropagator.extract(
|
||||
ROOT_CONTEXT,
|
||||
carrier,
|
||||
|
|
|
@ -19,10 +19,8 @@ import {
|
|||
defaultTextMapSetter,
|
||||
TextMapPropagator,
|
||||
SpanContext,
|
||||
getSpanContext,
|
||||
setSpanContext,
|
||||
TextMapGetter,
|
||||
TextMapSetter,
|
||||
TextMapSetter, trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { Context, ROOT_CONTEXT } from '@opentelemetry/api';
|
||||
import * as assert from 'assert';
|
||||
|
@ -39,11 +37,11 @@ import { TraceState } from '../../src/trace/TraceState';
|
|||
|
||||
class DummyPropagator implements TextMapPropagator {
|
||||
inject(context: Context, carrier: any, setter: TextMapSetter<any>): void {
|
||||
carrier['dummy'] = getSpanContext(context);
|
||||
carrier['dummy'] = trace.getSpanContext(context);
|
||||
}
|
||||
extract(context: Context, carrier: any, getter: TextMapGetter<any>): Context {
|
||||
if (carrier['dummy']) {
|
||||
return setSpanContext(context, carrier['dummy']);
|
||||
return trace.setSpanContext(context, carrier['dummy']);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
@ -75,7 +73,7 @@ describe('Composite Propagator', () => {
|
|||
traceFlags: 1,
|
||||
traceState: new TraceState('foo=bar'),
|
||||
};
|
||||
ctxWithSpanContext = setSpanContext(ROOT_CONTEXT, spanContext);
|
||||
ctxWithSpanContext = trace.setSpanContext(ROOT_CONTEXT, spanContext);
|
||||
});
|
||||
|
||||
it('should inject context using all configured propagators', () => {
|
||||
|
@ -123,7 +121,7 @@ describe('Composite Propagator', () => {
|
|||
const composite = new CompositePropagator({
|
||||
propagators: [new DummyPropagator(), new HttpTraceContextPropagator()],
|
||||
});
|
||||
const spanContext = getSpanContext(
|
||||
const spanContext = trace.getSpanContext(
|
||||
composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -145,7 +143,7 @@ describe('Composite Propagator', () => {
|
|||
new HttpTraceContextPropagator(),
|
||||
],
|
||||
});
|
||||
const spanContext = getSpanContext(
|
||||
const spanContext = trace.getSpanContext(
|
||||
composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
import {
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getSpanContext,
|
||||
INVALID_SPANID,
|
||||
INVALID_TRACEID,
|
||||
ROOT_CONTEXT,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
SpanContext, trace,
|
||||
TraceFlags,
|
||||
} from '@opentelemetry/api';
|
||||
import * as assert from 'assert';
|
||||
|
@ -51,7 +49,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
};
|
||||
|
||||
httpTraceContext.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -71,7 +69,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
};
|
||||
|
||||
httpTraceContext.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -90,7 +88,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
};
|
||||
|
||||
httpTraceContext.inject(
|
||||
suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
suppressTracing(trace.setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -107,7 +105,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
};
|
||||
|
||||
httpTraceContext.inject(
|
||||
suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
suppressTracing(trace.setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -120,7 +118,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
it('should extract context of a sampled span from carrier', () => {
|
||||
carrier[TRACE_PARENT_HEADER] =
|
||||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -135,7 +133,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
it('should extract context of a sampled span from carrier using a future version', () => {
|
||||
carrier[TRACE_PARENT_HEADER] =
|
||||
'cc-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -150,7 +148,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
it('should extract context of a sampled span from carrier using a future version and future fields', () => {
|
||||
carrier[TRACE_PARENT_HEADER] =
|
||||
'cc-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01-what-the-future-will-be-like';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -164,7 +162,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
|
||||
it('returns null if traceparent header is missing', () => {
|
||||
assert.deepStrictEqual(
|
||||
getSpanContext(
|
||||
trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
),
|
||||
undefined
|
||||
|
@ -174,7 +172,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
it('returns null if traceparent header is invalid', () => {
|
||||
carrier[TRACE_PARENT_HEADER] = 'invalid!';
|
||||
assert.deepStrictEqual(
|
||||
getSpanContext(
|
||||
trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
),
|
||||
undefined
|
||||
|
@ -187,7 +185,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01-extra';
|
||||
|
||||
assert.deepStrictEqual(
|
||||
getSpanContext(
|
||||
trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
),
|
||||
undefined
|
||||
|
@ -198,7 +196,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
carrier[TRACE_PARENT_HEADER] = [
|
||||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01',
|
||||
];
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
|
@ -213,7 +211,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
carrier[TRACE_PARENT_HEADER] =
|
||||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01';
|
||||
carrier[TRACE_STATE_HEADER] = 'foo=bar,baz=qux';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -231,7 +229,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
carrier[TRACE_PARENT_HEADER] =
|
||||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01';
|
||||
carrier[TRACE_STATE_HEADER] = ['foo=bar,baz=qux', 'quux=quuz'];
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
|
@ -285,7 +283,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
Object.getOwnPropertyNames(testCases).forEach(testCase => {
|
||||
carrier[TRACE_PARENT_HEADER] = testCases[testCase];
|
||||
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(extractedSpanContext, undefined, testCase);
|
||||
|
@ -296,7 +294,7 @@ describe('HttpTraceContextPropagator', () => {
|
|||
carrier[TRACE_PARENT_HEADER] =
|
||||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01';
|
||||
carrier[TRACE_STATE_HEADER] = 'foo=1 \t , \t bar=2, \t baz=3 ';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import * as assert from 'assert';
|
|||
import * as api from '@opentelemetry/api';
|
||||
import { AlwaysOnSampler } from '../../src/trace/sampler/AlwaysOnSampler';
|
||||
import { ParentBasedSampler } from '../../src/trace/sampler/ParentBasedSampler';
|
||||
import { TraceFlags, SpanKind, setSpanContext } from '@opentelemetry/api';
|
||||
import { TraceFlags, SpanKind, trace } from '@opentelemetry/api';
|
||||
import { AlwaysOffSampler } from '../../src/trace/sampler/AlwaysOffSampler';
|
||||
import { TraceIdRatioBasedSampler } from '../../src';
|
||||
|
||||
|
@ -58,7 +58,7 @@ describe('ParentBasedSampler', () => {
|
|||
};
|
||||
assert.deepStrictEqual(
|
||||
sampler.shouldSample(
|
||||
setSpanContext(api.ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(api.ROOT_CONTEXT, spanContext),
|
||||
traceId,
|
||||
spanName,
|
||||
SpanKind.CLIENT,
|
||||
|
@ -76,7 +76,7 @@ describe('ParentBasedSampler', () => {
|
|||
|
||||
assert.deepStrictEqual(
|
||||
sampler.shouldSample(
|
||||
setSpanContext(api.ROOT_CONTEXT, api.INVALID_SPAN_CONTEXT),
|
||||
trace.setSpanContext(api.ROOT_CONTEXT, api.INVALID_SPAN_CONTEXT),
|
||||
traceId,
|
||||
spanName,
|
||||
SpanKind.CLIENT,
|
||||
|
@ -117,7 +117,7 @@ describe('ParentBasedSampler', () => {
|
|||
};
|
||||
assert.deepStrictEqual(
|
||||
sampler.shouldSample(
|
||||
setSpanContext(api.ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(api.ROOT_CONTEXT, spanContext),
|
||||
traceId,
|
||||
spanName,
|
||||
SpanKind.CLIENT,
|
||||
|
@ -135,7 +135,7 @@ describe('ParentBasedSampler', () => {
|
|||
|
||||
assert.deepStrictEqual(
|
||||
sampler.shouldSample(
|
||||
setSpanContext(api.ROOT_CONTEXT, api.INVALID_SPAN_CONTEXT),
|
||||
trace.setSpanContext(api.ROOT_CONTEXT, api.INVALID_SPAN_CONTEXT),
|
||||
traceId,
|
||||
spanName,
|
||||
SpanKind.CLIENT,
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/api-metrics": "0.19.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
@ -63,7 +63,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.2.12",
|
||||
|
|
|
@ -111,10 +111,12 @@ export function mockValueRecorder(): metrics.Metric<metrics.BoundValueRecorder>
|
|||
export const mockedReadableSpan: ReadableSpan = {
|
||||
name: 'documentFetch',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
},
|
||||
parentSpanId: '78a8915098864388',
|
||||
startTime: [1574120165, 429803070],
|
||||
|
@ -127,6 +129,7 @@ export const mockedReadableSpan: ReadableSpan = {
|
|||
context: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '78a8915098864388',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
},
|
||||
attributes: { component: 'document-load' },
|
||||
},
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/api-metrics": "0.19.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
@ -63,7 +63,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/proto-loader": "^0.6.0",
|
||||
|
|
|
@ -95,10 +95,12 @@ const parentIdHex = '78a8915098864388';
|
|||
export const mockedReadableSpan: ReadableSpan = {
|
||||
name: 'documentFetch',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: traceIdHex,
|
||||
spanId: spanIdHex,
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: traceIdHex,
|
||||
spanId: spanIdHex,
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
},
|
||||
parentSpanId: parentIdHex,
|
||||
startTime: [1574120165, 429803070],
|
||||
|
@ -111,6 +113,7 @@ export const mockedReadableSpan: ReadableSpan = {
|
|||
context: {
|
||||
traceId: traceIdHex,
|
||||
spanId: parentIdHex,
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
},
|
||||
attributes: { component: 'document-load' },
|
||||
},
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -82,7 +82,7 @@
|
|||
"webpack-merge": "5.7.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api-metrics": "0.19.0",
|
||||
|
|
|
@ -174,17 +174,17 @@ export function toCollectorSpan(
|
|||
): opentelemetryProto.trace.v1.Span {
|
||||
return {
|
||||
traceId: useHex
|
||||
? span.spanContext.traceId
|
||||
: core.hexToBase64(span.spanContext.traceId),
|
||||
? span.spanContext().traceId
|
||||
: core.hexToBase64(span.spanContext().traceId),
|
||||
spanId: useHex
|
||||
? span.spanContext.spanId
|
||||
: core.hexToBase64(span.spanContext.spanId),
|
||||
? span.spanContext().spanId
|
||||
: core.hexToBase64(span.spanContext().spanId),
|
||||
parentSpanId: span.parentSpanId
|
||||
? useHex
|
||||
? span.parentSpanId
|
||||
: core.hexToBase64(span.parentSpanId)
|
||||
: undefined,
|
||||
traceState: toCollectorTraceState(span.spanContext.traceState),
|
||||
traceState: toCollectorTraceState(span.spanContext().traceState),
|
||||
name: span.name,
|
||||
kind: toCollectorKind(span.kind),
|
||||
startTimeUnixNano: core.hrTimeToNanoseconds(span.startTime),
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SpanAttributes, TimedEvent } from '@opentelemetry/api';
|
||||
import { SpanAttributes } from '@opentelemetry/api';
|
||||
import { TimedEvent } from '@opentelemetry/tracing';
|
||||
import * as assert from 'assert';
|
||||
import * as transform from '../../src/transform';
|
||||
import {
|
||||
|
|
|
@ -157,10 +157,12 @@ const parentIdHex = '78a8915098864388';
|
|||
export const mockedReadableSpan: ReadableSpan = {
|
||||
name: 'documentFetch',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: ()=> {
|
||||
return {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
}
|
||||
},
|
||||
parentSpanId: '78a8915098864388',
|
||||
startTime: [1574120165, 429803070],
|
||||
|
@ -173,6 +175,7 @@ export const mockedReadableSpan: ReadableSpan = {
|
|||
context: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '78a8915098864388',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
},
|
||||
attributes: { component: 'document-load' },
|
||||
},
|
||||
|
@ -228,10 +231,12 @@ export const basicTrace: ReadableSpan[] = [
|
|||
{
|
||||
name: 'span1',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
},
|
||||
parentSpanId: '78a8915098864388',
|
||||
startTime: [1574120165, 429803070],
|
||||
|
@ -248,10 +253,12 @@ export const basicTrace: ReadableSpan[] = [
|
|||
{
|
||||
name: 'span2',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: 'f64fa53e5e107261',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: 'f64fa53e5e107261',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
},
|
||||
parentSpanId: '78a8915098864388',
|
||||
startTime: [1575120165, 439803070],
|
||||
|
@ -268,10 +275,12 @@ export const basicTrace: ReadableSpan[] = [
|
|||
{
|
||||
name: 'span3',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '07261f64fa53e5e1',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '07261f64fa53e5e1',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
},
|
||||
parentSpanId: 'a891578098864388',
|
||||
startTime: [1575120165, 439803070],
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/resources": "0.19.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
@ -56,7 +56,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -40,7 +40,7 @@ const DEFAULT_FLAGS = 0x1;
|
|||
* @param span Span to be translated
|
||||
*/
|
||||
export function spanToThrift(span: ReadableSpan): ThriftSpan {
|
||||
const traceId = span.spanContext.traceId.padStart(32, '0');
|
||||
const traceId = span.spanContext().traceId.padStart(32, '0');
|
||||
const traceIdHigh = traceId.slice(0, 16);
|
||||
const traceIdLow = traceId.slice(16);
|
||||
const parentSpan = span.parentSpanId
|
||||
|
@ -105,11 +105,11 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
|
|||
return {
|
||||
traceIdLow: Utils.encodeInt64(traceIdLow),
|
||||
traceIdHigh: Utils.encodeInt64(traceIdHigh),
|
||||
spanId: Utils.encodeInt64(span.spanContext.spanId),
|
||||
spanId: Utils.encodeInt64(span.spanContext().spanId),
|
||||
parentSpanId: parentSpan,
|
||||
operationName: span.name,
|
||||
references: spanLinksToThriftRefs(span.links, span.parentSpanId),
|
||||
flags: span.spanContext.traceFlags || DEFAULT_FLAGS,
|
||||
flags: span.spanContext().traceFlags || DEFAULT_FLAGS,
|
||||
startTime: Utils.encodeInt64(hrTimeToMicroseconds(span.startTime)),
|
||||
duration: Utils.encodeInt64(hrTimeToMicroseconds(span.duration)),
|
||||
tags: spanTags,
|
||||
|
|
|
@ -108,10 +108,12 @@ describe('JaegerExporter', () => {
|
|||
const readableSpan: ReadableSpan = {
|
||||
name: 'my-span1',
|
||||
kind: api.SpanKind.CLIENT,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [1566156729, 709],
|
||||
endTime: [1566156731, 709],
|
||||
|
|
|
@ -24,10 +24,12 @@ import { hrTimeToMicroseconds } from '@opentelemetry/core';
|
|||
import { SpanStatusCode, TraceFlags } from '@opentelemetry/api';
|
||||
|
||||
describe('transform', () => {
|
||||
const spanContext = {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
const spanContext = () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
};
|
||||
|
||||
describe('spanToThrift', () => {
|
||||
|
@ -52,6 +54,7 @@ describe('transform', () => {
|
|||
context: {
|
||||
traceId: 'a4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '3e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
},
|
||||
attributes: {
|
||||
testBool: true,
|
||||
|
@ -217,6 +220,7 @@ describe('transform', () => {
|
|||
context: {
|
||||
traceId: 'a4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '3e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -249,10 +253,12 @@ describe('transform', () => {
|
|||
const readableSpan: ReadableSpan = {
|
||||
name: 'my-span1',
|
||||
kind: api.SpanKind.CLIENT,
|
||||
spanContext: {
|
||||
traceId: '92b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: '92b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [1566156729, 709],
|
||||
endTime: [1566156731, 709],
|
||||
|
@ -304,6 +310,7 @@ describe('transform', () => {
|
|||
context: {
|
||||
traceId: 'a4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '3e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
},
|
||||
attributes: {
|
||||
testBool: true,
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -53,7 +53,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api-metrics": "0.19.0",
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -80,7 +80,7 @@
|
|||
"webpack-merge": "5.7.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -43,10 +43,10 @@ export function toZipkinSpan(
|
|||
statusDescriptionTagName: string
|
||||
): zipkinTypes.Span {
|
||||
const zipkinSpan: zipkinTypes.Span = {
|
||||
traceId: span.spanContext.traceId,
|
||||
traceId: span.spanContext().traceId,
|
||||
parentId: span.parentSpanId,
|
||||
name: span.name,
|
||||
id: span.spanContext.spanId,
|
||||
id: span.spanContext().spanId,
|
||||
kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
|
||||
timestamp: hrTimeToMicroseconds(span.startTime),
|
||||
duration: hrTimeToMicroseconds(span.duration),
|
||||
|
|
|
@ -85,7 +85,7 @@ describe('transform', () => {
|
|||
duration: hrTimeToMicroseconds(
|
||||
hrTimeDuration(span.startTime, span.endTime)
|
||||
),
|
||||
id: span.spanContext.spanId,
|
||||
id: span.spanContext().spanId,
|
||||
localEndpoint: {
|
||||
serviceName: 'my-service',
|
||||
},
|
||||
|
@ -100,7 +100,7 @@ describe('transform', () => {
|
|||
'telemetry.sdk.version': VERSION,
|
||||
},
|
||||
timestamp: hrTimeToMicroseconds(span.startTime),
|
||||
traceId: span.spanContext.traceId,
|
||||
traceId: span.spanContext().traceId,
|
||||
});
|
||||
});
|
||||
it("should skip parentSpanId if doesn't exist", () => {
|
||||
|
@ -125,7 +125,7 @@ describe('transform', () => {
|
|||
duration: hrTimeToMicroseconds(
|
||||
hrTimeDuration(span.startTime, span.endTime)
|
||||
),
|
||||
id: span.spanContext.spanId,
|
||||
id: span.spanContext().spanId,
|
||||
localEndpoint: {
|
||||
serviceName: 'my-service',
|
||||
},
|
||||
|
@ -138,7 +138,7 @@ describe('transform', () => {
|
|||
'telemetry.sdk.version': VERSION,
|
||||
},
|
||||
timestamp: hrTimeToMicroseconds(span.startTime),
|
||||
traceId: span.spanContext.traceId,
|
||||
traceId: span.spanContext().traceId,
|
||||
});
|
||||
});
|
||||
// SpanKind mapping tests
|
||||
|
@ -173,7 +173,7 @@ describe('transform', () => {
|
|||
duration: hrTimeToMicroseconds(
|
||||
hrTimeDuration(span.startTime, span.endTime)
|
||||
),
|
||||
id: span.spanContext.spanId,
|
||||
id: span.spanContext().spanId,
|
||||
localEndpoint: {
|
||||
serviceName: 'my-service',
|
||||
},
|
||||
|
@ -186,7 +186,7 @@ describe('transform', () => {
|
|||
'telemetry.sdk.version': VERSION,
|
||||
},
|
||||
timestamp: hrTimeToMicroseconds(span.startTime),
|
||||
traceId: span.spanContext.traceId,
|
||||
traceId: span.spanContext().traceId,
|
||||
});
|
||||
})
|
||||
);
|
||||
|
|
|
@ -23,10 +23,12 @@ import { Span } from '../src/types';
|
|||
export const mockedReadableSpan: ReadableSpan = {
|
||||
name: 'documentFetch',
|
||||
kind: 0,
|
||||
spanContext: {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
|
||||
spanId: '5e107261f64fa53e',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
},
|
||||
parentSpanId: '78a8915098864388',
|
||||
startTime: [1574120165, 429803070],
|
||||
|
@ -53,7 +55,7 @@ export function ensureHeadersContain(
|
|||
assert.strictEqual(
|
||||
v,
|
||||
actual[k],
|
||||
`Expected ${actual} to contain ${k}: ${v}`
|
||||
`Expected ${ actual } to contain ${ k }: ${ v }`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,10 +37,12 @@ function getReadableSpan() {
|
|||
const readableSpan: ReadableSpan = {
|
||||
name: 'my-span',
|
||||
kind: api.SpanKind.INTERNAL,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -134,10 +136,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
name: 'my-span',
|
||||
kind: api.SpanKind.INTERNAL,
|
||||
parentSpanId,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -164,10 +168,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
const span2: ReadableSpan = {
|
||||
name: 'my-span',
|
||||
kind: api.SpanKind.SERVER,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -200,7 +206,7 @@ describe('Zipkin Exporter - node', () => {
|
|||
},
|
||||
],
|
||||
duration: duration * MICROS_PER_SECS,
|
||||
id: span1.spanContext.spanId,
|
||||
id: span1.spanContext().spanId,
|
||||
localEndpoint: {
|
||||
serviceName: 'my-service',
|
||||
},
|
||||
|
@ -212,12 +218,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
'ot.status_code': 'OK',
|
||||
},
|
||||
timestamp: startTime * MICROS_PER_SECS,
|
||||
traceId: span1.spanContext.traceId,
|
||||
traceId: span1.spanContext().traceId,
|
||||
},
|
||||
// Span 2
|
||||
{
|
||||
duration: duration * MICROS_PER_SECS,
|
||||
id: span2.spanContext.spanId,
|
||||
id: span2.spanContext().spanId,
|
||||
kind: 'SERVER',
|
||||
localEndpoint: {
|
||||
serviceName: 'my-service',
|
||||
|
@ -227,7 +233,7 @@ describe('Zipkin Exporter - node', () => {
|
|||
'ot.status_code': 'OK',
|
||||
},
|
||||
timestamp: hrTimeToMicroseconds([startTime, 0]),
|
||||
traceId: span2.spanContext.traceId,
|
||||
traceId: span2.spanContext().traceId,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
@ -320,10 +326,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
name: 'my-span',
|
||||
kind: api.SpanKind.INTERNAL,
|
||||
parentSpanId,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -350,10 +358,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
const span2: ReadableSpan = {
|
||||
name: 'my-span',
|
||||
kind: api.SpanKind.SERVER,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -392,10 +402,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
name: 'my-span',
|
||||
kind: api.SpanKind.INTERNAL,
|
||||
parentSpanId,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -424,10 +436,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
const span2: ReadableSpan = {
|
||||
name: 'my-span',
|
||||
kind: api.SpanKind.SERVER,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -494,10 +508,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
name: 'my-span',
|
||||
kind: api.SpanKind.INTERNAL,
|
||||
parentSpanId,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -526,10 +542,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
const span2: ReadableSpan = {
|
||||
name: 'my-span',
|
||||
kind: api.SpanKind.SERVER,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -583,10 +601,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
name: 'my-span',
|
||||
kind: api.SpanKind.INTERNAL,
|
||||
parentSpanId,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
@ -614,10 +634,12 @@ describe('Zipkin Exporter - node', () => {
|
|||
const span2: ReadableSpan = {
|
||||
name: 'my-span',
|
||||
kind: api.SpanKind.SERVER,
|
||||
spanContext: {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
spanContext: () => {
|
||||
return {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
},
|
||||
startTime: [startTime, 0],
|
||||
endTime: [startTime + duration, 0],
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/context-zone": "0.19.0",
|
||||
"@opentelemetry/propagator-b3": "0.19.0",
|
||||
"@opentelemetry/tracing": "0.19.0",
|
||||
|
@ -78,7 +78,7 @@
|
|||
"webpack-merge": "5.7.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -114,7 +114,7 @@ export class FetchInstrumentation extends InstrumentationBase<
|
|||
{
|
||||
startTime: corsPreFlightRequest[web.PerformanceTimingNames.FETCH_START],
|
||||
},
|
||||
api.setSpan(api.context.active(), span)
|
||||
api.trace.setSpan(api.context.active(), span)
|
||||
);
|
||||
web.addSpanNetworkEvents(childSpan, corsPreFlightRequest);
|
||||
childSpan.end(
|
||||
|
@ -385,7 +385,7 @@ export class FetchInstrumentation extends InstrumentationBase<
|
|||
|
||||
return new Promise((resolve, reject) => {
|
||||
return api.context.with(
|
||||
api.setSpan(api.context.active(), createdSpan),
|
||||
api.trace.setSpan(api.context.active(), createdSpan),
|
||||
() => {
|
||||
plugin._addHeaders(options, url);
|
||||
plugin._tasksCount++;
|
||||
|
|
|
@ -234,7 +234,7 @@ describe('fetch', () => {
|
|||
);
|
||||
|
||||
rootSpan = webTracerWithZone.startSpan('root');
|
||||
api.context.with(api.setSpan(api.context.active(), rootSpan), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), rootSpan), () => {
|
||||
fakeNow = 0;
|
||||
void getData(fileUrl, method)
|
||||
.then(
|
||||
|
@ -310,7 +310,7 @@ describe('fetch', () => {
|
|||
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
span.parentSpanId,
|
||||
rootSpan.context().spanId,
|
||||
rootSpan.spanContext().spanId,
|
||||
'parent span is not root span'
|
||||
);
|
||||
});
|
||||
|
@ -430,7 +430,7 @@ describe('fetch', () => {
|
|||
const parentSpan: tracing.ReadableSpan = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
span.parentSpanId,
|
||||
parentSpan.spanContext.spanId,
|
||||
parentSpan.spanContext().spanId,
|
||||
'parent span is not root span'
|
||||
);
|
||||
});
|
||||
|
@ -509,17 +509,17 @@ describe('fetch', () => {
|
|||
const span: api.Span = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
lastResponse.headers[X_B3_TRACE_ID],
|
||||
span.context().traceId,
|
||||
span.spanContext().traceId,
|
||||
`trace header '${X_B3_TRACE_ID}' not set`
|
||||
);
|
||||
assert.strictEqual(
|
||||
lastResponse.headers[X_B3_SPAN_ID],
|
||||
span.context().spanId,
|
||||
span.spanContext().spanId,
|
||||
`trace header '${X_B3_SPAN_ID}' not set`
|
||||
);
|
||||
assert.strictEqual(
|
||||
lastResponse.headers[X_B3_SAMPLED],
|
||||
String(span.context().traceFlags),
|
||||
String(span.spanContext().traceFlags),
|
||||
`trace header '${X_B3_SAMPLED}' not set`
|
||||
);
|
||||
});
|
||||
|
@ -693,7 +693,7 @@ describe('fetch', () => {
|
|||
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
span.parentSpanId,
|
||||
rootSpan.context().spanId,
|
||||
rootSpan.spanContext().spanId,
|
||||
'parent span is not root span'
|
||||
);
|
||||
});
|
||||
|
@ -712,7 +712,7 @@ describe('fetch', () => {
|
|||
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
span.parentSpanId,
|
||||
rootSpan.context().spanId,
|
||||
rootSpan.spanContext().spanId,
|
||||
'parent span is not root span'
|
||||
);
|
||||
});
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
"devDependencies": {
|
||||
"@grpc/grpc-js": "1.3.0",
|
||||
"@grpc/proto-loader": "0.6.1",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/context-async-hooks": "0.19.0",
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
"@opentelemetry/node": "0.19.0",
|
||||
|
@ -66,7 +66,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api-metrics": "0.19.0",
|
||||
|
|
|
@ -35,12 +35,12 @@ import {
|
|||
} from './types';
|
||||
import {
|
||||
context,
|
||||
SpanOptions,
|
||||
SpanKind,
|
||||
diag,
|
||||
propagation,
|
||||
ROOT_CONTEXT,
|
||||
setSpan,
|
||||
diag,
|
||||
SpanOptions,
|
||||
SpanKind,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import {
|
||||
shouldNotTraceServerCall,
|
||||
|
@ -200,7 +200,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
|
|||
[AttributeNames.GRPC_KIND]: spanOptions.kind,
|
||||
});
|
||||
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
handleServerFunction.call(
|
||||
self,
|
||||
span,
|
||||
|
@ -292,7 +292,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
|
|||
const span = instrumentation.tracer.startSpan(name, {
|
||||
kind: SpanKind.CLIENT,
|
||||
});
|
||||
return context.with(setSpan(context.active(), span), () =>
|
||||
return context.with(trace.setSpan(context.active(), span), () =>
|
||||
makeGrpcClientRemoteCall(original, args, metadata, this)(span)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -31,11 +31,11 @@ import {
|
|||
import { GrpcInstrumentationConfig } from '../types';
|
||||
import {
|
||||
context,
|
||||
diag,
|
||||
propagation,
|
||||
SpanOptions,
|
||||
SpanKind,
|
||||
setSpan,
|
||||
diag,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import {
|
||||
clientStreamAndUnaryHandler,
|
||||
|
@ -205,7 +205,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
|
|||
[AttributeNames.GRPC_KIND]: spanOptions.kind,
|
||||
});
|
||||
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
switch (type) {
|
||||
case 'unary':
|
||||
case 'client_stream':
|
||||
|
@ -299,7 +299,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
|
|||
const span = instrumentation.tracer.startSpan(name, {
|
||||
kind: SpanKind.CLIENT,
|
||||
});
|
||||
return context.with(setSpan(context.active(), span), () =>
|
||||
return context.with(trace.setSpan(context.active(), span), () =>
|
||||
makeGrpcClientRemoteCall(
|
||||
grpcClient,
|
||||
original,
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
import {
|
||||
context,
|
||||
SpanKind,
|
||||
propagation,
|
||||
setSpan,
|
||||
getSpan,
|
||||
propagation, trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { HttpTraceContextPropagator } from '@opentelemetry/core';
|
||||
import { NodeTracerProvider } from '@opentelemetry/node';
|
||||
|
@ -512,8 +510,8 @@ export const runTests = (
|
|||
const span = provider
|
||||
.getTracer('default')
|
||||
.startSpan('TestSpan', { kind: SpanKind.PRODUCER });
|
||||
return context.with(setSpan(context.active(), span), async () => {
|
||||
const rootSpan = getSpan(context.active());
|
||||
return context.with(trace.setSpan(context.active(), span), async () => {
|
||||
const rootSpan = trace.getSpan(context.active());
|
||||
if (!rootSpan) {
|
||||
return assert.ok(false);
|
||||
}
|
||||
|
@ -547,11 +545,11 @@ export const runTests = (
|
|||
);
|
||||
assertPropagation(serverSpan, clientSpan);
|
||||
assert.strictEqual(
|
||||
rootSpan.context().traceId,
|
||||
serverSpan.spanContext.traceId
|
||||
rootSpan.spanContext().traceId,
|
||||
serverSpan.spanContext().traceId
|
||||
);
|
||||
assert.strictEqual(
|
||||
rootSpan.context().spanId,
|
||||
rootSpan.spanContext().spanId,
|
||||
clientSpan.parentSpanId
|
||||
);
|
||||
}
|
||||
|
@ -608,8 +606,8 @@ export const runTests = (
|
|||
const span = provider
|
||||
.getTracer('default')
|
||||
.startSpan('TestSpan', { kind: SpanKind.PRODUCER });
|
||||
return context.with(setSpan(context.active(), span), async () => {
|
||||
const rootSpan = getSpan(context.active());
|
||||
return context.with(trace.setSpan(context.active(), span), async () => {
|
||||
const rootSpan = trace.getSpan(context.active());
|
||||
if (!rootSpan) {
|
||||
return assert.ok(false);
|
||||
}
|
||||
|
@ -636,11 +634,11 @@ export const runTests = (
|
|||
assertSpan(moduleName, clientSpan, SpanKind.CLIENT, validations);
|
||||
assertPropagation(serverSpan, clientSpan);
|
||||
assert.strictEqual(
|
||||
rootSpan.context().traceId,
|
||||
serverSpan.spanContext.traceId
|
||||
rootSpan.spanContext().traceId,
|
||||
serverSpan.spanContext().traceId
|
||||
);
|
||||
assert.strictEqual(
|
||||
rootSpan.context().spanId,
|
||||
rootSpan.spanContext().spanId,
|
||||
clientSpan.parentSpanId
|
||||
);
|
||||
});
|
||||
|
|
|
@ -39,8 +39,8 @@ export const assertSpan = (
|
|||
kind: SpanKind,
|
||||
validations: { name: string; status: grpc.status | grpcJs.status }
|
||||
) => {
|
||||
assert.strictEqual(span.spanContext.traceId.length, 32);
|
||||
assert.strictEqual(span.spanContext.spanId.length, 16);
|
||||
assert.strictEqual(span.spanContext().traceId.length, 32);
|
||||
assert.strictEqual(span.spanContext().spanId.length, 16);
|
||||
assert.strictEqual(span.kind, kind);
|
||||
|
||||
assert.ok(span.endTime);
|
||||
|
@ -52,7 +52,7 @@ export const assertSpan = (
|
|||
assert.ok(hrTimeToMilliseconds(span.endTime) > 0);
|
||||
|
||||
if (span.kind === SpanKind.SERVER) {
|
||||
assert.ok(span.spanContext);
|
||||
assert.ok(span.spanContext());
|
||||
}
|
||||
|
||||
// validations
|
||||
|
@ -68,8 +68,8 @@ export const assertPropagation = (
|
|||
incomingSpan: ReadableSpan,
|
||||
outgoingSpan: ReadableSpan
|
||||
) => {
|
||||
const targetSpanContext = incomingSpan.spanContext;
|
||||
const sourceSpanContext = outgoingSpan.spanContext;
|
||||
const targetSpanContext = incomingSpan.spanContext();
|
||||
const sourceSpanContext = outgoingSpan.spanContext();
|
||||
assert.strictEqual(targetSpanContext.traceId, sourceSpanContext.traceId);
|
||||
assert.strictEqual(incomingSpan.parentSpanId, sourceSpanContext.spanId);
|
||||
assert.strictEqual(
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/context-async-hooks": "0.19.0",
|
||||
"@opentelemetry/node": "0.19.0",
|
||||
"@opentelemetry/tracing": "0.19.0",
|
||||
|
@ -68,7 +68,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -21,11 +21,9 @@ import {
|
|||
SpanKind,
|
||||
SpanOptions,
|
||||
SpanStatus,
|
||||
setSpan,
|
||||
ROOT_CONTEXT,
|
||||
getSpan,
|
||||
NOOP_TRACER,
|
||||
diag,
|
||||
diag, trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { suppressTracing } from '@opentelemetry/core';
|
||||
import type * as http from 'http';
|
||||
|
@ -412,7 +410,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
|
|||
ctx
|
||||
);
|
||||
|
||||
return context.with(setSpan(ctx, span), () => {
|
||||
return context.with(trace.setSpan(ctx, span), () => {
|
||||
context.bind(request);
|
||||
context.bind(response);
|
||||
|
||||
|
@ -535,7 +533,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
|
|||
const span = instrumentation._startHttpSpan(operationName, spanOptions);
|
||||
|
||||
const parentContext = context.active();
|
||||
const requestContext = setSpan(parentContext, span);
|
||||
const requestContext = trace.setSpan(parentContext, span);
|
||||
|
||||
if (!optionsParsed.headers) {
|
||||
optionsParsed.headers = {};
|
||||
|
@ -590,13 +588,13 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
|
|||
: this._getConfig().requireParentforIncomingSpans;
|
||||
|
||||
let span: Span;
|
||||
const currentSpan = getSpan(ctx);
|
||||
const currentSpan = trace.getSpan(ctx);
|
||||
|
||||
if (requireParent === true && currentSpan === undefined) {
|
||||
// TODO: Refactor this when a solution is found in
|
||||
// https://github.com/open-telemetry/opentelemetry-specification/issues/530
|
||||
span = NOOP_TRACER.startSpan(name, options, ctx);
|
||||
} else if (requireParent === true && currentSpan?.context().isRemote) {
|
||||
} else if (requireParent === true && currentSpan?.spanContext().isRemote) {
|
||||
span = currentSpan;
|
||||
} else {
|
||||
span = this.tracer.startSpan(name, options, ctx);
|
||||
|
|
|
@ -18,9 +18,7 @@ import {
|
|||
context,
|
||||
propagation,
|
||||
Span as ISpan,
|
||||
SpanKind,
|
||||
getSpan,
|
||||
setSpan,
|
||||
SpanKind, trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { NodeTracerProvider } from '@opentelemetry/node';
|
||||
import {
|
||||
|
@ -332,7 +330,7 @@ describe('HttpInstrumentation', () => {
|
|||
doNock(hostname, testPath, 200, 'Ok');
|
||||
const name = 'TestRootSpan';
|
||||
const span = provider.getTracer('default').startSpan(name);
|
||||
return context.with(setSpan(context.active(), span), async () => {
|
||||
return context.with(trace.setSpan(context.active(), span), async () => {
|
||||
const result = await httpRequest.get(
|
||||
`${protocol}://${hostname}${testPath}`
|
||||
);
|
||||
|
@ -353,13 +351,13 @@ describe('HttpInstrumentation', () => {
|
|||
assert.strictEqual(spans.length, 2);
|
||||
assert.strictEqual(reqSpan.name, 'HTTP GET');
|
||||
assert.strictEqual(
|
||||
localSpan.spanContext.traceId,
|
||||
reqSpan.spanContext.traceId
|
||||
localSpan.spanContext().traceId,
|
||||
reqSpan.spanContext().traceId
|
||||
);
|
||||
assertSpan(reqSpan, SpanKind.CLIENT, validations);
|
||||
assert.notStrictEqual(
|
||||
localSpan.spanContext.spanId,
|
||||
reqSpan.spanContext.spanId
|
||||
localSpan.spanContext().spanId,
|
||||
reqSpan.spanContext().spanId
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -375,7 +373,7 @@ describe('HttpInstrumentation', () => {
|
|||
);
|
||||
const name = 'TestRootSpan';
|
||||
const span = provider.getTracer('default').startSpan(name);
|
||||
return context.with(setSpan(context.active(), span), async () => {
|
||||
return context.with(trace.setSpan(context.active(), span), async () => {
|
||||
const result = await httpRequest.get(
|
||||
`${protocol}://${hostname}${testPath}`
|
||||
);
|
||||
|
@ -396,13 +394,13 @@ describe('HttpInstrumentation', () => {
|
|||
assert.strictEqual(spans.length, 2);
|
||||
assert.strictEqual(reqSpan.name, 'HTTP GET');
|
||||
assert.strictEqual(
|
||||
localSpan.spanContext.traceId,
|
||||
reqSpan.spanContext.traceId
|
||||
localSpan.spanContext().traceId,
|
||||
reqSpan.spanContext().traceId
|
||||
);
|
||||
assertSpan(reqSpan, SpanKind.CLIENT, validations);
|
||||
assert.notStrictEqual(
|
||||
localSpan.spanContext.spanId,
|
||||
reqSpan.spanContext.spanId
|
||||
localSpan.spanContext().spanId,
|
||||
reqSpan.spanContext().spanId
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -414,14 +412,14 @@ describe('HttpInstrumentation', () => {
|
|||
doNock(hostname, testPath, 200, 'Ok', num);
|
||||
const name = 'TestRootSpan';
|
||||
const span = provider.getTracer('default').startSpan(name);
|
||||
await context.with(setSpan(context.active(), span), async () => {
|
||||
await context.with(trace.setSpan(context.active(), span), async () => {
|
||||
for (let i = 0; i < num; i++) {
|
||||
await httpRequest.get(`${protocol}://${hostname}${testPath}`);
|
||||
const spans = memoryExporter.getFinishedSpans();
|
||||
assert.strictEqual(spans[i].name, 'HTTP GET');
|
||||
assert.strictEqual(
|
||||
span.context().traceId,
|
||||
spans[i].spanContext.traceId
|
||||
span.spanContext().traceId,
|
||||
spans[i].spanContext().traceId
|
||||
);
|
||||
}
|
||||
span.end();
|
||||
|
@ -706,16 +704,16 @@ describe('HttpInstrumentation', () => {
|
|||
});
|
||||
|
||||
it('should not set span as active in context for outgoing request', done => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
http.get(`${protocol}://${hostname}:${serverPort}/test`, res => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
|
||||
res.on('data', () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -813,7 +811,7 @@ describe('HttpInstrumentation', () => {
|
|||
const span = tracer.startSpan('parentSpan', {
|
||||
kind: SpanKind.INTERNAL,
|
||||
});
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
httpRequest
|
||||
.get(`${protocol}://${hostname}:${serverPort}${testPath}`)
|
||||
.then(result => {
|
||||
|
|
|
@ -20,7 +20,7 @@ import {
|
|||
propagation,
|
||||
Span as ISpan,
|
||||
SpanKind,
|
||||
setSpan,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
|
||||
import { ContextManager } from '@opentelemetry/api';
|
||||
|
@ -312,7 +312,7 @@ describe('HttpsInstrumentation', () => {
|
|||
doNock(hostname, testPath, 200, 'Ok');
|
||||
const name = 'TestRootSpan';
|
||||
const span = tracer.startSpan(name);
|
||||
return context.with(setSpan(context.active(), span), async () => {
|
||||
return context.with(trace.setSpan(context.active(), span), async () => {
|
||||
const result = await httpsRequest.get(
|
||||
`${protocol}://${hostname}${testPath}`
|
||||
);
|
||||
|
@ -333,13 +333,13 @@ describe('HttpsInstrumentation', () => {
|
|||
assert.strictEqual(spans.length, 2);
|
||||
assert.strictEqual(reqSpan.name, 'HTTPS GET');
|
||||
assert.strictEqual(
|
||||
localSpan.spanContext.traceId,
|
||||
reqSpan.spanContext.traceId
|
||||
localSpan.spanContext().traceId,
|
||||
reqSpan.spanContext().traceId
|
||||
);
|
||||
assertSpan(reqSpan, SpanKind.CLIENT, validations);
|
||||
assert.notStrictEqual(
|
||||
localSpan.spanContext.spanId,
|
||||
reqSpan.spanContext.spanId
|
||||
localSpan.spanContext().spanId,
|
||||
reqSpan.spanContext().spanId
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -355,7 +355,7 @@ describe('HttpsInstrumentation', () => {
|
|||
);
|
||||
const name = 'TestRootSpan';
|
||||
const span = tracer.startSpan(name);
|
||||
return context.with(setSpan(context.active(), span), async () => {
|
||||
return context.with(trace.setSpan(context.active(), span), async () => {
|
||||
const result = await httpsRequest.get(
|
||||
`${protocol}://${hostname}${testPath}`
|
||||
);
|
||||
|
@ -376,13 +376,13 @@ describe('HttpsInstrumentation', () => {
|
|||
assert.strictEqual(spans.length, 2);
|
||||
assert.strictEqual(reqSpan.name, 'HTTPS GET');
|
||||
assert.strictEqual(
|
||||
localSpan.spanContext.traceId,
|
||||
reqSpan.spanContext.traceId
|
||||
localSpan.spanContext().traceId,
|
||||
reqSpan.spanContext().traceId
|
||||
);
|
||||
assertSpan(reqSpan, SpanKind.CLIENT, validations);
|
||||
assert.notStrictEqual(
|
||||
localSpan.spanContext.spanId,
|
||||
reqSpan.spanContext.spanId
|
||||
localSpan.spanContext().spanId,
|
||||
reqSpan.spanContext().spanId
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -394,14 +394,14 @@ describe('HttpsInstrumentation', () => {
|
|||
doNock(hostname, testPath, 200, 'Ok', num);
|
||||
const name = 'TestRootSpan';
|
||||
const span = tracer.startSpan(name);
|
||||
await context.with(setSpan(context.active(), span), async () => {
|
||||
await context.with(trace.setSpan(context.active(), span), async () => {
|
||||
for (let i = 0; i < num; i++) {
|
||||
await httpsRequest.get(`${protocol}://${hostname}${testPath}`);
|
||||
const spans = memoryExporter.getFinishedSpans();
|
||||
assert.strictEqual(spans[i].name, 'HTTPS GET');
|
||||
assert.strictEqual(
|
||||
span.context().traceId,
|
||||
spans[i].spanContext.traceId
|
||||
span.spanContext().traceId,
|
||||
spans[i].spanContext().traceId
|
||||
);
|
||||
}
|
||||
span.end();
|
||||
|
|
|
@ -15,10 +15,8 @@
|
|||
*/
|
||||
import {
|
||||
Context,
|
||||
TextMapPropagator,
|
||||
TextMapPropagator, trace,
|
||||
TraceFlags,
|
||||
getSpanContext,
|
||||
setSpanContext,
|
||||
} from '@opentelemetry/api';
|
||||
import type * as http from 'http';
|
||||
|
||||
|
@ -33,12 +31,12 @@ export class DummyPropagation implements TextMapPropagator {
|
|||
isRemote: true,
|
||||
};
|
||||
if (extractedSpanContext.traceId && extractedSpanContext.spanId) {
|
||||
return setSpanContext(context, extractedSpanContext);
|
||||
return trace.setSpanContext(context, extractedSpanContext);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
inject(context: Context, headers: { [custom: string]: string }): void {
|
||||
const spanContext = getSpanContext(context);
|
||||
const spanContext = trace.getSpanContext(context);
|
||||
if (!spanContext) return;
|
||||
headers[DummyPropagation.TRACE_CONTEXT_KEY] = spanContext.traceId;
|
||||
headers[DummyPropagation.SPAN_CONTEXT_KEY] = spanContext.spanId;
|
||||
|
|
|
@ -39,8 +39,8 @@ export const assertSpan = (
|
|||
component: string;
|
||||
}
|
||||
) => {
|
||||
assert.strictEqual(span.spanContext.traceId.length, 32);
|
||||
assert.strictEqual(span.spanContext.spanId.length, 16);
|
||||
assert.strictEqual(span.spanContext().traceId.length, 32);
|
||||
assert.strictEqual(span.spanContext().spanId.length, 16);
|
||||
assert.strictEqual(span.kind, kind);
|
||||
assert.strictEqual(
|
||||
span.name,
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/context-zone": "0.19.0",
|
||||
"@opentelemetry/propagator-b3": "0.19.0",
|
||||
"@opentelemetry/tracing": "0.19.0",
|
||||
|
@ -77,7 +77,7 @@
|
|||
"webpack-merge": "5.7.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -139,7 +139,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRe
|
|||
span: api.Span,
|
||||
corsPreFlightRequest: PerformanceResourceTiming
|
||||
): void {
|
||||
api.context.with(api.setSpan(api.context.active(), span), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
|
||||
const childSpan = this.tracer.startSpan('CORS Preflight', {
|
||||
startTime: corsPreFlightRequest[PTN.FETCH_START],
|
||||
});
|
||||
|
@ -480,7 +480,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRe
|
|||
|
||||
if (currentSpan && spanUrl) {
|
||||
api.context.with(
|
||||
api.setSpan(api.context.active(), currentSpan),
|
||||
api.trace.setSpan(api.context.active(), currentSpan),
|
||||
() => {
|
||||
plugin._tasksCount++;
|
||||
xhrMem.sendStartTime = hrTime();
|
||||
|
|
|
@ -220,7 +220,7 @@ describe('xhr', () => {
|
|||
);
|
||||
|
||||
rootSpan = webTracerWithZone.startSpan('root');
|
||||
api.context.with(api.setSpan(api.context.active(), rootSpan), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), rootSpan), () => {
|
||||
getData(
|
||||
new XMLHttpRequest(),
|
||||
fileUrl,
|
||||
|
@ -270,7 +270,7 @@ describe('xhr', () => {
|
|||
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
span.parentSpanId,
|
||||
rootSpan.context().spanId,
|
||||
rootSpan.spanContext().spanId,
|
||||
'parent span is not root span'
|
||||
);
|
||||
});
|
||||
|
@ -408,7 +408,7 @@ describe('xhr', () => {
|
|||
const parentSpan: tracing.ReadableSpan = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
span.parentSpanId,
|
||||
parentSpan.spanContext.spanId,
|
||||
parentSpan.spanContext().spanId,
|
||||
'parent span is not root span'
|
||||
);
|
||||
});
|
||||
|
@ -504,17 +504,17 @@ describe('xhr', () => {
|
|||
const span: api.Span = exportSpy.args[0][0][0];
|
||||
assert.strictEqual(
|
||||
requests[0].requestHeaders[X_B3_TRACE_ID],
|
||||
span.context().traceId,
|
||||
span.spanContext().traceId,
|
||||
`trace header '${X_B3_TRACE_ID}' not set`
|
||||
);
|
||||
assert.strictEqual(
|
||||
requests[0].requestHeaders[X_B3_SPAN_ID],
|
||||
span.context().spanId,
|
||||
span.spanContext().spanId,
|
||||
`trace header '${X_B3_SPAN_ID}' not set`
|
||||
);
|
||||
assert.strictEqual(
|
||||
requests[0].requestHeaders[X_B3_SAMPLED],
|
||||
String(span.context().traceFlags),
|
||||
String(span.spanContext().traceFlags),
|
||||
`trace header '${X_B3_SAMPLED}' not set`
|
||||
);
|
||||
});
|
||||
|
@ -537,17 +537,17 @@ describe('xhr', () => {
|
|||
const span: api.Span = exportSpy.args[1][0][0];
|
||||
assert.strictEqual(
|
||||
requests[0].requestHeaders[X_B3_TRACE_ID],
|
||||
span.context().traceId,
|
||||
span.spanContext().traceId,
|
||||
`trace header '${X_B3_TRACE_ID}' not set`
|
||||
);
|
||||
assert.strictEqual(
|
||||
requests[0].requestHeaders[X_B3_SPAN_ID],
|
||||
span.context().spanId,
|
||||
span.spanContext().spanId,
|
||||
`trace header '${X_B3_SPAN_ID}' not set`
|
||||
);
|
||||
assert.strictEqual(
|
||||
requests[0].requestHeaders[X_B3_SAMPLED],
|
||||
String(span.context().traceFlags),
|
||||
String(span.spanContext().traceFlags),
|
||||
`trace header '${X_B3_SAMPLED}' not set`
|
||||
);
|
||||
});
|
||||
|
@ -646,7 +646,7 @@ describe('xhr', () => {
|
|||
);
|
||||
const reusableReq = new XMLHttpRequest();
|
||||
api.context.with(
|
||||
api.setSpan(api.context.active(), rootSpan),
|
||||
api.trace.setSpan(api.context.active(), rootSpan),
|
||||
() => {
|
||||
getData(
|
||||
reusableReq,
|
||||
|
@ -663,7 +663,7 @@ describe('xhr', () => {
|
|||
);
|
||||
|
||||
api.context.with(
|
||||
api.setSpan(api.context.active(), rootSpan),
|
||||
api.trace.setSpan(api.context.active(), rootSpan),
|
||||
() => {
|
||||
getData(
|
||||
reusableReq,
|
||||
|
@ -793,7 +793,7 @@ describe('xhr', () => {
|
|||
});
|
||||
|
||||
function timedOutRequest(done: any) {
|
||||
api.context.with(api.setSpan(api.context.active(), rootSpan), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), rootSpan), () => {
|
||||
void getData(
|
||||
new XMLHttpRequest(),
|
||||
url,
|
||||
|
@ -810,7 +810,7 @@ describe('xhr', () => {
|
|||
}
|
||||
|
||||
function abortedRequest(done: any) {
|
||||
api.context.with(api.setSpan(api.context.active(), rootSpan), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), rootSpan), () => {
|
||||
void getData(new XMLHttpRequest(), url, () => {}, testAsync).then(
|
||||
() => {
|
||||
fakeNow = 0;
|
||||
|
@ -825,7 +825,7 @@ describe('xhr', () => {
|
|||
}
|
||||
|
||||
function erroredRequest(done: any) {
|
||||
api.context.with(api.setSpan(api.context.active(), rootSpan), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), rootSpan), () => {
|
||||
void getData(
|
||||
new XMLHttpRequest(),
|
||||
url,
|
||||
|
@ -848,7 +848,7 @@ describe('xhr', () => {
|
|||
}
|
||||
|
||||
function networkErrorRequest(done: any) {
|
||||
api.context.with(api.setSpan(api.context.active(), rootSpan), () => {
|
||||
api.context.with(api.trace.setSpan(api.context.active(), rootSpan), () => {
|
||||
void getData(new XMLHttpRequest(), url, () => {}, testAsync).then(
|
||||
() => {
|
||||
fakeNow = 0;
|
||||
|
|
|
@ -65,11 +65,11 @@
|
|||
"shimmer": "^1.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.14.0",
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/semver": "7.3.5",
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/lodash.merge": "4.6.6",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
@ -59,7 +59,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api-metrics": "0.19.0",
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/resources": "0.19.0",
|
||||
"@opentelemetry/semantic-conventions": "0.19.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
|
@ -60,7 +60,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/context-async-hooks": "0.19.0",
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
import {
|
||||
context,
|
||||
TraceFlags,
|
||||
setSpan,
|
||||
setSpanContext,
|
||||
getSpan,
|
||||
propagation,
|
||||
propagation, trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { AlwaysOnSampler, AlwaysOffSampler } from '@opentelemetry/core';
|
||||
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
|
||||
|
@ -99,7 +96,7 @@ describe('NodeTracerProvider', () => {
|
|||
sampler: new AlwaysOffSampler(),
|
||||
});
|
||||
const span = provider.getTracer('default').startSpan('my-span');
|
||||
assert.strictEqual(span.context().traceFlags, TraceFlags.NONE);
|
||||
assert.strictEqual(span.spanContext().traceFlags, TraceFlags.NONE);
|
||||
assert.strictEqual(span.isRecording(), false);
|
||||
});
|
||||
|
||||
|
@ -109,7 +106,7 @@ describe('NodeTracerProvider', () => {
|
|||
});
|
||||
const span = provider.getTracer('default').startSpan('my-span');
|
||||
assert.ok(span instanceof Span);
|
||||
assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(span.spanContext().traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(span.isRecording(), true);
|
||||
});
|
||||
|
||||
|
@ -121,7 +118,7 @@ describe('NodeTracerProvider', () => {
|
|||
const sampledParent = provider.getTracer('default').startSpan(
|
||||
'not-sampled-span',
|
||||
{},
|
||||
setSpanContext(ROOT_CONTEXT, {
|
||||
trace.setSpanContext(ROOT_CONTEXT, {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.NONE,
|
||||
|
@ -129,16 +126,16 @@ describe('NodeTracerProvider', () => {
|
|||
);
|
||||
assert.ok(sampledParent instanceof Span);
|
||||
assert.strictEqual(
|
||||
sampledParent.context().traceFlags,
|
||||
sampledParent.spanContext().traceFlags,
|
||||
TraceFlags.SAMPLED
|
||||
);
|
||||
assert.strictEqual(sampledParent.isRecording(), true);
|
||||
|
||||
const span = provider
|
||||
.getTracer('default')
|
||||
.startSpan('child-span', {}, setSpan(ROOT_CONTEXT, sampledParent));
|
||||
.startSpan('child-span', {}, trace.setSpan(ROOT_CONTEXT, sampledParent));
|
||||
assert.ok(span instanceof Span);
|
||||
assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(span.spanContext().traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(span.isRecording(), true);
|
||||
});
|
||||
|
||||
|
@ -158,46 +155,46 @@ describe('NodeTracerProvider', () => {
|
|||
it('should run context with AsyncHooksContextManager context manager', done => {
|
||||
provider = new NodeTracerProvider({});
|
||||
const span = provider.getTracer('default').startSpan('my-span');
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), span);
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), span);
|
||||
return done();
|
||||
});
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
});
|
||||
|
||||
it('should run context with AsyncHooksContextManager context manager with multiple spans', done => {
|
||||
provider = new NodeTracerProvider({});
|
||||
const span = provider.getTracer('default').startSpan('my-span');
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), span);
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), span);
|
||||
|
||||
const span1 = provider.getTracer('default').startSpan('my-span1');
|
||||
|
||||
context.with(setSpan(context.active(), span1), () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), span1);
|
||||
context.with(trace.setSpan(context.active(), span1), () => {
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), span1);
|
||||
assert.deepStrictEqual(
|
||||
span1.context().traceId,
|
||||
span.context().traceId
|
||||
span1.spanContext().traceId,
|
||||
span.spanContext().traceId
|
||||
);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
// when span ended.
|
||||
// @todo: below check is not running.
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
});
|
||||
|
||||
it('should find correct context with promises', async () => {
|
||||
provider = new NodeTracerProvider();
|
||||
const span = provider.getTracer('default').startSpan('my-span');
|
||||
await context.with(setSpan(context.active(), span), async () => {
|
||||
await context.with(trace.setSpan(context.active(), span), async () => {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await sleep(5).then(() => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), span);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), span);
|
||||
});
|
||||
}
|
||||
});
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -206,10 +203,10 @@ describe('NodeTracerProvider', () => {
|
|||
const provider = new NodeTracerProvider({});
|
||||
const span = provider.getTracer('default').startSpan('my-span');
|
||||
const fn = () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), span);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), span);
|
||||
return done();
|
||||
};
|
||||
const patchedFn = context.bind(fn, setSpan(context.active(), span));
|
||||
const patchedFn = context.bind(fn, trace.setSpan(context.active(), span));
|
||||
return patchedFn();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -46,10 +46,10 @@
|
|||
"@opentelemetry/core": "^0.19.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"codecov": "3.8.1",
|
||||
|
|
|
@ -16,11 +16,10 @@
|
|||
|
||||
import {
|
||||
Context,
|
||||
getSpanContext,
|
||||
isSpanContextValid,
|
||||
isValidSpanId,
|
||||
isValidTraceId,
|
||||
setSpanContext,
|
||||
trace,
|
||||
TextMapGetter,
|
||||
TextMapPropagator,
|
||||
TextMapSetter,
|
||||
|
@ -95,7 +94,7 @@ function getTraceFlags(
|
|||
*/
|
||||
export class B3MultiPropagator implements TextMapPropagator {
|
||||
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
|
||||
const spanContext = getSpanContext(context);
|
||||
const spanContext = trace.getSpanContext(context);
|
||||
if (
|
||||
!spanContext ||
|
||||
!isSpanContextValid(spanContext) ||
|
||||
|
@ -135,7 +134,7 @@ export class B3MultiPropagator implements TextMapPropagator {
|
|||
isValidSampledValue(traceFlags)
|
||||
) {
|
||||
context = context.setValue(B3_DEBUG_FLAG_KEY, debug);
|
||||
return setSpanContext(context, {
|
||||
return trace.setSpanContext(context, {
|
||||
traceId,
|
||||
spanId,
|
||||
isRemote: true,
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
|
||||
import {
|
||||
Context,
|
||||
getSpanContext,
|
||||
isSpanContextValid,
|
||||
isValidSpanId,
|
||||
isValidTraceId,
|
||||
setSpanContext,
|
||||
TextMapGetter,
|
||||
TextMapPropagator,
|
||||
TextMapSetter,
|
||||
TextMapSetter, trace,
|
||||
TraceFlags,
|
||||
} from '@opentelemetry/api';
|
||||
import { isTracingSuppressed } from '@opentelemetry/core';
|
||||
|
@ -52,7 +50,7 @@ function convertToTraceFlags(samplingState: string | undefined): TraceFlags {
|
|||
*/
|
||||
export class B3SinglePropagator implements TextMapPropagator {
|
||||
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
|
||||
const spanContext = getSpanContext(context);
|
||||
const spanContext = trace.getSpanContext(context);
|
||||
if (
|
||||
!spanContext ||
|
||||
!isSpanContextValid(spanContext) ||
|
||||
|
@ -85,7 +83,7 @@ export class B3SinglePropagator implements TextMapPropagator {
|
|||
context = context.setValue(B3_DEBUG_FLAG_KEY, samplingState);
|
||||
}
|
||||
|
||||
return setSpanContext(context, {
|
||||
return trace.setSpanContext(context, {
|
||||
traceId,
|
||||
spanId,
|
||||
isRemote: true,
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
import {
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getSpanContext,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
trace,
|
||||
TraceFlags,
|
||||
} from '@opentelemetry/api';
|
||||
import { ROOT_CONTEXT } from '@opentelemetry/api';
|
||||
|
@ -52,7 +51,7 @@ describe('B3MultiPropagator', () => {
|
|||
};
|
||||
|
||||
b3Propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -88,7 +87,7 @@ describe('B3MultiPropagator', () => {
|
|||
};
|
||||
|
||||
b3Propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -110,7 +109,7 @@ describe('B3MultiPropagator', () => {
|
|||
const contextWithDebug = ROOT_CONTEXT.setValue(B3_DEBUG_FLAG_KEY, '1');
|
||||
|
||||
b3Propagator.inject(
|
||||
setSpanContext(contextWithDebug, spanContext),
|
||||
trace.setSpanContext(contextWithDebug, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -130,7 +129,7 @@ describe('B3MultiPropagator', () => {
|
|||
traceFlags: TraceFlags.NONE,
|
||||
};
|
||||
b3Propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, emptySpanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, emptySpanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -147,7 +146,7 @@ describe('B3MultiPropagator', () => {
|
|||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
b3Propagator.inject(
|
||||
suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
suppressTracing(trace.setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -167,7 +166,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
traceId: '0af7651916cd43dd8448eb211c80319c',
|
||||
|
@ -188,7 +187,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -210,7 +209,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -232,7 +231,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -256,7 +255,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -281,7 +280,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -304,7 +303,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -327,7 +326,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -350,7 +349,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
@ -368,7 +367,7 @@ describe('B3MultiPropagator', () => {
|
|||
it('should return undefined', () => {
|
||||
carrier[X_B3_TRACE_ID] = undefined;
|
||||
carrier[X_B3_SPAN_ID] = 'b7ad6b7169203331';
|
||||
const context = getSpanContext(
|
||||
const context = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(context, undefined);
|
||||
|
@ -379,7 +378,7 @@ describe('B3MultiPropagator', () => {
|
|||
it('should return undefined', () => {
|
||||
carrier[X_B3_TRACE_ID] = '0af7651916cd43dd8448eb211c80319c';
|
||||
carrier[X_B3_SPAN_ID] = undefined;
|
||||
const context = getSpanContext(
|
||||
const context = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(context, undefined);
|
||||
|
@ -391,7 +390,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier[X_B3_TRACE_ID] = '0af7651916cd43dd8448eb211c80319c';
|
||||
carrier[X_B3_SPAN_ID] = 'b7ad6b7169203331';
|
||||
carrier[X_B3_SAMPLED] = '2';
|
||||
const context = getSpanContext(
|
||||
const context = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(context, undefined);
|
||||
|
@ -400,7 +399,7 @@ describe('B3MultiPropagator', () => {
|
|||
|
||||
describe('AND b3 header is missing', () => {
|
||||
it('should return undefined', () => {
|
||||
const context = getSpanContext(
|
||||
const context = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(context, undefined);
|
||||
|
@ -411,7 +410,7 @@ describe('B3MultiPropagator', () => {
|
|||
it('should return undefined', () => {
|
||||
carrier[X_B3_TRACE_ID] = 'invalid!';
|
||||
carrier[X_B3_SPAN_ID] = 'b7ad6b7169203331';
|
||||
const context = getSpanContext(
|
||||
const context = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(context, undefined);
|
||||
|
@ -428,7 +427,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
traceId: '0af7651916cd43dd8448eb211c80319c',
|
||||
|
@ -477,7 +476,7 @@ describe('B3MultiPropagator', () => {
|
|||
|
||||
Object.getOwnPropertyNames(testCases).forEach(testCase => {
|
||||
carrier[X_B3_TRACE_ID] = testCases[testCase];
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.deepStrictEqual(extractedSpanContext, undefined, testCase);
|
||||
|
@ -513,7 +512,7 @@ describe('B3MultiPropagator', () => {
|
|||
carrier,
|
||||
defaultTextMapGetter
|
||||
);
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'b7ad6b7169203331',
|
||||
|
|
|
@ -17,11 +17,10 @@
|
|||
import {
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getSpanContext,
|
||||
ROOT_CONTEXT,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
TraceFlags,
|
||||
ROOT_CONTEXT,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { suppressTracing } from '@opentelemetry/core';
|
||||
import * as assert from 'assert';
|
||||
|
@ -56,7 +55,7 @@ describe('B3Propagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -77,7 +76,7 @@ describe('B3Propagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -100,7 +99,7 @@ describe('B3Propagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
suppressTracing(trace.setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -128,7 +127,7 @@ describe('B3Propagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '80f198ee56343ba864fe8b2a57d3eff7',
|
||||
|
@ -144,7 +143,7 @@ describe('B3Propagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
|
@ -160,7 +159,7 @@ describe('B3Propagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '80f198ee56343ba864fe8b2a57d3eff7',
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
import {
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getSpanContext,
|
||||
INVALID_SPANID,
|
||||
INVALID_TRACEID,
|
||||
ROOT_CONTEXT,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
TraceFlags,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { suppressTracing } from '@opentelemetry/core';
|
||||
import * as assert from 'assert';
|
||||
|
@ -48,7 +47,7 @@ describe('B3SinglePropagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -65,7 +64,7 @@ describe('B3SinglePropagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -84,7 +83,7 @@ describe('B3SinglePropagator', () => {
|
|||
const context = ROOT_CONTEXT.setValue(B3_DEBUG_FLAG_KEY, 'd');
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(context, spanContext),
|
||||
trace.setSpanContext(context, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -101,7 +100,7 @@ describe('B3SinglePropagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -117,7 +116,7 @@ describe('B3SinglePropagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -133,7 +132,7 @@ describe('B3SinglePropagator', () => {
|
|||
};
|
||||
|
||||
propagator.inject(
|
||||
suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
suppressTracing(trace.setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -155,7 +154,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '80f198ee56343ba864fe8b2a57d3eff7',
|
||||
|
@ -176,7 +175,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '80f198ee56343ba864fe8b2a57d3eff7',
|
||||
|
@ -197,7 +196,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '80f198ee56343ba864fe8b2a57d3eff7',
|
||||
|
@ -217,7 +216,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '00000000000000004aaba1a52cf8ee09',
|
||||
|
@ -238,7 +237,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(extractedSpanContext, {
|
||||
spanId: 'e457b5a2e4d86bd1',
|
||||
traceId: '80f198ee56343ba864fe8b2a57d3eff7',
|
||||
|
@ -259,7 +258,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(undefined, extractedSpanContext);
|
||||
});
|
||||
|
||||
|
@ -274,7 +273,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(undefined, extractedSpanContext);
|
||||
});
|
||||
|
||||
|
@ -289,7 +288,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(undefined, extractedSpanContext);
|
||||
});
|
||||
|
||||
|
@ -304,7 +303,7 @@ describe('B3SinglePropagator', () => {
|
|||
defaultTextMapGetter
|
||||
);
|
||||
|
||||
const extractedSpanContext = getSpanContext(context);
|
||||
const extractedSpanContext = trace.getSpanContext(context);
|
||||
assert.deepStrictEqual(undefined, extractedSpanContext);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -71,7 +71,7 @@
|
|||
"webpack": "4.46.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0"
|
||||
|
|
|
@ -16,15 +16,12 @@
|
|||
|
||||
import {
|
||||
Context,
|
||||
getBaggage,
|
||||
getSpanContext,
|
||||
setBaggage,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
TextMapGetter,
|
||||
TextMapPropagator,
|
||||
TextMapSetter,
|
||||
createBaggage,
|
||||
propagation,
|
||||
trace,
|
||||
TraceFlags,
|
||||
} from '@opentelemetry/api';
|
||||
import { isTracingSuppressed } from '@opentelemetry/core';
|
||||
|
@ -59,8 +56,8 @@ export class JaegerPropagator implements TextMapPropagator {
|
|||
}
|
||||
|
||||
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
|
||||
const spanContext = getSpanContext(context);
|
||||
const baggage = getBaggage(context);
|
||||
const spanContext = trace.getSpanContext(context);
|
||||
const baggage = propagation.getBaggage(context);
|
||||
if (spanContext && isTracingSuppressed(context) === false) {
|
||||
const traceFlags = `0${(
|
||||
spanContext.traceFlags || TraceFlags.NONE
|
||||
|
@ -105,20 +102,20 @@ export class JaegerPropagator implements TextMapPropagator {
|
|||
if (typeof uberTraceId === 'string') {
|
||||
const spanContext = deserializeSpanContext(uberTraceId);
|
||||
if (spanContext) {
|
||||
newContext = setSpanContext(newContext, spanContext);
|
||||
newContext = trace.setSpanContext(newContext, spanContext);
|
||||
}
|
||||
}
|
||||
if (baggageValues.length === 0) return newContext;
|
||||
|
||||
// if baggage values are present, inject it into the current baggage
|
||||
let currentBaggage = getBaggage(context) ?? createBaggage();
|
||||
let currentBaggage = propagation.getBaggage(context) ?? propagation.createBaggage();
|
||||
for (const baggageEntry of baggageValues) {
|
||||
if (baggageEntry.value === undefined) continue;
|
||||
currentBaggage = currentBaggage.setEntry(baggageEntry.key, {
|
||||
value: decodeURIComponent(baggageEntry.value),
|
||||
});
|
||||
}
|
||||
newContext = setBaggage(newContext, currentBaggage);
|
||||
newContext = propagation.setBaggage(newContext, currentBaggage);
|
||||
|
||||
return newContext;
|
||||
}
|
||||
|
|
|
@ -15,16 +15,12 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
createBaggage,
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getBaggage,
|
||||
getSpanContext,
|
||||
defaultTextMapSetter, propagation,
|
||||
ROOT_CONTEXT,
|
||||
setBaggage,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
TextMapGetter,
|
||||
trace,
|
||||
TraceFlags,
|
||||
} from '@opentelemetry/api';
|
||||
import { suppressTracing } from '@opentelemetry/core';
|
||||
|
@ -54,7 +50,7 @@ describe('JaegerPropagator', () => {
|
|||
};
|
||||
|
||||
jaegerPropagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -72,7 +68,7 @@ describe('JaegerPropagator', () => {
|
|||
};
|
||||
|
||||
customJaegerPropagator.inject(
|
||||
setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
trace.setSpanContext(ROOT_CONTEXT, spanContext),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -90,7 +86,7 @@ describe('JaegerPropagator', () => {
|
|||
};
|
||||
|
||||
jaegerPropagator.inject(
|
||||
suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
suppressTracing(trace.setSpanContext(ROOT_CONTEXT, spanContext)),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -98,7 +94,7 @@ describe('JaegerPropagator', () => {
|
|||
});
|
||||
|
||||
it('should propagate baggage with url encoded values', () => {
|
||||
const baggage = createBaggage({
|
||||
const baggage = propagation.createBaggage({
|
||||
test: {
|
||||
value: '1',
|
||||
},
|
||||
|
@ -108,7 +104,7 @@ describe('JaegerPropagator', () => {
|
|||
});
|
||||
|
||||
jaegerPropagator.inject(
|
||||
setBaggage(ROOT_CONTEXT, baggage),
|
||||
propagation.setBaggage(ROOT_CONTEXT, baggage),
|
||||
carrier,
|
||||
defaultTextMapSetter
|
||||
);
|
||||
|
@ -124,7 +120,7 @@ describe('JaegerPropagator', () => {
|
|||
it('should extract context of a sampled span from carrier', () => {
|
||||
carrier[UBER_TRACE_ID_HEADER] =
|
||||
'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -139,7 +135,7 @@ describe('JaegerPropagator', () => {
|
|||
it('should extract context of a sampled span from carrier with 1 bit flag', () => {
|
||||
carrier[UBER_TRACE_ID_HEADER] =
|
||||
'9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:1';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -154,7 +150,7 @@ describe('JaegerPropagator', () => {
|
|||
it('should extract context of a sampled span from UTF-8 encoded carrier', () => {
|
||||
carrier[UBER_TRACE_ID_HEADER] =
|
||||
'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -169,7 +165,7 @@ describe('JaegerPropagator', () => {
|
|||
it('should use custom header if provided', () => {
|
||||
carrier[customHeader] =
|
||||
'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01';
|
||||
const extractedSpanContext = getSpanContext(
|
||||
const extractedSpanContext = trace.getSpanContext(
|
||||
customJaegerPropagator.extract(
|
||||
ROOT_CONTEXT,
|
||||
carrier,
|
||||
|
@ -187,7 +183,7 @@ describe('JaegerPropagator', () => {
|
|||
|
||||
it('returns undefined if UBER_TRACE_ID_HEADER header is missing', () => {
|
||||
assert.deepStrictEqual(
|
||||
getSpanContext(
|
||||
trace.getSpanContext(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
),
|
||||
undefined
|
||||
|
@ -197,7 +193,7 @@ describe('JaegerPropagator', () => {
|
|||
it('returns undefined if UBER_TRACE_ID_HEADER header is invalid', () => {
|
||||
carrier[UBER_TRACE_ID_HEADER] = 'invalid!';
|
||||
assert.deepStrictEqual(
|
||||
getSpanContext(
|
||||
trace.getSpanContext(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
),
|
||||
undefined
|
||||
|
@ -207,7 +203,7 @@ describe('JaegerPropagator', () => {
|
|||
it('should extract baggage from carrier', () => {
|
||||
carrier[`${UBER_BAGGAGE_HEADER_PREFIX}-test`] = 'value';
|
||||
carrier[`${UBER_BAGGAGE_HEADER_PREFIX}-myuser`] = '%25id%25';
|
||||
const extractedBaggage = getBaggage(
|
||||
const extractedBaggage = propagation.getBaggage(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -222,9 +218,9 @@ describe('JaegerPropagator', () => {
|
|||
it('should extract baggage from carrier and not override current one', () => {
|
||||
carrier[`${UBER_BAGGAGE_HEADER_PREFIX}-test`] = 'value';
|
||||
carrier[`${UBER_BAGGAGE_HEADER_PREFIX}-myuser`] = '%25id%25';
|
||||
const extractedBaggage = getBaggage(
|
||||
const extractedBaggage = propagation.getBaggage(
|
||||
jaegerPropagator.extract(
|
||||
setBaggage(ROOT_CONTEXT, createBaggage({ one: { value: 'two' } })),
|
||||
propagation.setBaggage(ROOT_CONTEXT, propagation.createBaggage({ one: { value: 'two' } })),
|
||||
carrier,
|
||||
defaultTextMapGetter
|
||||
)
|
||||
|
@ -243,7 +239,7 @@ describe('JaegerPropagator', () => {
|
|||
|
||||
it('should handle invalid baggage from carrier (undefined)', () => {
|
||||
carrier[`${UBER_BAGGAGE_HEADER_PREFIX}-test`] = undefined;
|
||||
const extractedBaggage = getBaggage(
|
||||
const extractedBaggage = propagation.getBaggage(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
@ -253,7 +249,7 @@ describe('JaegerPropagator', () => {
|
|||
|
||||
it('should handle invalid baggage from carrier (array)', () => {
|
||||
carrier[`${UBER_BAGGAGE_HEADER_PREFIX}-test`] = ['one', 'two'];
|
||||
const extractedBaggage = getBaggage(
|
||||
const extractedBaggage = propagation.getBaggage(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -54,7 +54,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
@ -54,7 +54,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/resources": "0.19.0",
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
"@types/sinon": "9.0.11",
|
||||
|
@ -63,7 +63,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -51,10 +51,10 @@
|
|||
"@opentelemetry/tracing": "0.19.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/context-async-hooks": "0.19.0",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@opentelemetry/tracing": "0.19.0",
|
||||
"@opentelemetry/propagator-b3": "0.19.0",
|
||||
"@opentelemetry/propagator-jaeger": "0.19.0",
|
||||
|
@ -55,7 +55,7 @@
|
|||
"typescript": "4.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
import * as api from '@opentelemetry/api';
|
||||
import * as opentracing from 'opentracing';
|
||||
import {
|
||||
createBaggage,
|
||||
SpanAttributes,
|
||||
SpanAttributeValue,
|
||||
TextMapPropagator,
|
||||
|
@ -54,9 +53,9 @@ function translateSpanOptions(
|
|||
function getContextWithParent(options: opentracing.SpanOptions) {
|
||||
if (options.childOf) {
|
||||
if (options.childOf instanceof SpanShim) {
|
||||
return api.setSpan(api.context.active(), options.childOf.getSpan());
|
||||
return api.trace.setSpan(api.context.active(), options.childOf.getSpan());
|
||||
} else if (options.childOf instanceof SpanContextShim) {
|
||||
return api.setSpanContext(
|
||||
return api.trace.setSpanContext(
|
||||
api.context.active(),
|
||||
options.childOf.getSpanContext()
|
||||
);
|
||||
|
@ -141,7 +140,7 @@ export class TracerShim extends opentracing.Tracer {
|
|||
getContextWithParent(options)
|
||||
);
|
||||
|
||||
let baggage: api.Baggage = createBaggage();
|
||||
let baggage: api.Baggage = api.propagation.createBaggage();
|
||||
if (options.childOf instanceof SpanShim) {
|
||||
const shimContext = options.childOf.context() as SpanContextShim;
|
||||
baggage = shimContext.getBaggage();
|
||||
|
@ -175,8 +174,8 @@ export class TracerShim extends opentracing.Tracer {
|
|||
|
||||
const propagator = this._getPropagator(format);
|
||||
if (propagator !== undefined) {
|
||||
const context = api.setBaggage(
|
||||
api.setSpanContext(api.ROOT_CONTEXT, oTelSpanContext),
|
||||
const context = api.propagation.setBaggage(
|
||||
api.trace.setSpanContext(api.ROOT_CONTEXT, oTelSpanContext),
|
||||
oTelSpanBaggage
|
||||
);
|
||||
propagator.inject(context, carrier, api.defaultTextMapSetter);
|
||||
|
@ -197,18 +196,18 @@ export class TracerShim extends opentracing.Tracer {
|
|||
carrier,
|
||||
api.defaultTextMapGetter
|
||||
);
|
||||
const spanContext = api.getSpanContext(context);
|
||||
const baggage = api.getBaggage(context);
|
||||
const spanContext = api.trace.getSpanContext(context);
|
||||
const baggage = api.propagation.getBaggage(context);
|
||||
|
||||
if (!spanContext) {
|
||||
return null;
|
||||
}
|
||||
return new SpanContextShim(spanContext, baggage || createBaggage());
|
||||
return new SpanContextShim(spanContext, baggage || api.propagation.createBaggage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private _getPropagator(format: string): TextMapPropagator | undefined {
|
||||
private _getPropagator(format: string): api.TextMapPropagator | undefined {
|
||||
switch (format) {
|
||||
case opentracing.FORMAT_TEXT_MAP:
|
||||
return this._propagators?.textMapPropagator ?? api.propagation;
|
||||
|
@ -235,7 +234,7 @@ export class SpanShim extends opentracing.Span {
|
|||
constructor(tracerShim: TracerShim, span: api.Span, baggage: api.Baggage) {
|
||||
super();
|
||||
this._span = span;
|
||||
this._contextShim = new SpanContextShim(span.context(), baggage);
|
||||
this._contextShim = new SpanContextShim(span.spanContext(), baggage);
|
||||
this._tracerShim = tracerShim;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,14 +25,12 @@ import {
|
|||
timeInputToHrTime,
|
||||
} from '@opentelemetry/core';
|
||||
import {
|
||||
createBaggage,
|
||||
defaultTextMapGetter,
|
||||
defaultTextMapSetter,
|
||||
getSpanContext,
|
||||
INVALID_SPAN_CONTEXT,
|
||||
propagation,
|
||||
ROOT_CONTEXT,
|
||||
setSpanContext,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import { performance } from 'perf_hooks';
|
||||
import { B3Propagator } from '@opentelemetry/propagator-b3';
|
||||
|
@ -148,7 +146,7 @@ describe('OpenTracing Shim', () => {
|
|||
it('injects HTTP carriers', () => {
|
||||
const carrier: { [key: string]: unknown } = {};
|
||||
shimTracer.inject(context, opentracing.FORMAT_HTTP_HEADERS, carrier);
|
||||
const extractedContext = getSpanContext(
|
||||
const extractedContext = trace.getSpanContext(
|
||||
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.ok(extractedContext !== null);
|
||||
|
@ -159,7 +157,7 @@ describe('OpenTracing Shim', () => {
|
|||
it('extracts HTTP carriers', () => {
|
||||
const carrier: { [key: string]: unknown } = {};
|
||||
jaegerPropagator.inject(
|
||||
setSpanContext(
|
||||
trace.setSpanContext(
|
||||
ROOT_CONTEXT,
|
||||
(context as SpanContextShim).getSpanContext()
|
||||
),
|
||||
|
@ -179,7 +177,7 @@ describe('OpenTracing Shim', () => {
|
|||
it('injects TextMap carriers', () => {
|
||||
const carrier: { [key: string]: unknown } = {};
|
||||
shimTracer.inject(context, opentracing.FORMAT_TEXT_MAP, carrier);
|
||||
const extractedContext = getSpanContext(
|
||||
const extractedContext = trace.getSpanContext(
|
||||
b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
|
||||
);
|
||||
assert.ok(extractedContext !== null);
|
||||
|
@ -190,7 +188,7 @@ describe('OpenTracing Shim', () => {
|
|||
it('extracts TextMap carriers', () => {
|
||||
const carrier: { [key: string]: unknown } = {};
|
||||
b3Propagator.inject(
|
||||
setSpanContext(
|
||||
trace.setSpanContext(
|
||||
ROOT_CONTEXT,
|
||||
(context as SpanContextShim).getSpanContext()
|
||||
),
|
||||
|
@ -268,7 +266,7 @@ describe('OpenTracing Shim', () => {
|
|||
|
||||
describe('SpanContextShim', () => {
|
||||
it('returns the correct context', () => {
|
||||
const shim = new SpanContextShim(INVALID_SPAN_CONTEXT, createBaggage());
|
||||
const shim = new SpanContextShim(INVALID_SPAN_CONTEXT, propagation.createBaggage());
|
||||
assert.strictEqual(shim.getSpanContext(), INVALID_SPAN_CONTEXT);
|
||||
assert.strictEqual(shim.toTraceId(), INVALID_SPAN_CONTEXT.traceId);
|
||||
assert.strictEqual(shim.toSpanId(), INVALID_SPAN_CONTEXT.spanId);
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0",
|
||||
"@opentelemetry/api": "^0.20.0",
|
||||
"@types/lodash.merge": "4.6.6",
|
||||
"@types/mocha": "8.2.2",
|
||||
"@types/node": "14.14.43",
|
||||
|
@ -78,7 +78,7 @@
|
|||
"webpack": "4.46.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.0.0-rc.0"
|
||||
"@opentelemetry/api": "^0.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "0.19.0",
|
||||
|
|
|
@ -39,7 +39,7 @@ import { ExceptionEventName } from './enums';
|
|||
export class Span implements api.Span, ReadableSpan {
|
||||
// Below properties are included to implement ReadableSpan for export
|
||||
// purposes but are not intended to be written-to directly.
|
||||
readonly spanContext: api.SpanContext;
|
||||
private readonly _spanContext: api.SpanContext;
|
||||
readonly kind: api.SpanKind;
|
||||
readonly parentSpanId?: string;
|
||||
readonly attributes: api.SpanAttributes = {};
|
||||
|
@ -70,7 +70,7 @@ export class Span implements api.Span, ReadableSpan {
|
|||
startTime: api.TimeInput = hrTime()
|
||||
) {
|
||||
this.name = spanName;
|
||||
this.spanContext = spanContext;
|
||||
this._spanContext = spanContext;
|
||||
this.parentSpanId = parentSpanId;
|
||||
this.kind = kind;
|
||||
this.links = links;
|
||||
|
@ -82,8 +82,8 @@ export class Span implements api.Span, ReadableSpan {
|
|||
this._spanProcessor.onStart(this, context);
|
||||
}
|
||||
|
||||
context(): api.SpanContext {
|
||||
return this.spanContext;
|
||||
spanContext(): api.SpanContext {
|
||||
return this._spanContext;
|
||||
}
|
||||
|
||||
setAttribute(key: string, value?: SpanAttributeValue): this;
|
||||
|
@ -229,8 +229,8 @@ export class Span implements api.Span, ReadableSpan {
|
|||
if (this._ended) {
|
||||
api.diag.warn(
|
||||
'Can not execute the operation on ended Span {traceId: %s, spanId: %s}',
|
||||
this.spanContext.traceId,
|
||||
this.spanContext.spanId
|
||||
this._spanContext.traceId,
|
||||
this._spanContext.spanId
|
||||
);
|
||||
}
|
||||
return this._ended;
|
||||
|
|
|
@ -54,6 +54,46 @@ export class Tracer implements api.Tracer {
|
|||
this.instrumentationLibrary = instrumentationLibrary;
|
||||
}
|
||||
|
||||
startActiveSpan<F extends (span: api.Span) => ReturnType<F>>(
|
||||
name: string,
|
||||
arg2: F | api.SpanOptions,
|
||||
arg3?: F | api.Context,
|
||||
arg4?: F
|
||||
): ReturnType<F> | undefined {
|
||||
let fn: F | undefined,
|
||||
options: api.SpanOptions | undefined,
|
||||
activeContext: api.Context | undefined;
|
||||
|
||||
if (arguments.length === 2 && typeof arg2 === 'function') {
|
||||
fn = arg2;
|
||||
} else if (
|
||||
arguments.length === 3 &&
|
||||
typeof arg2 === 'object' &&
|
||||
typeof arg3 === 'function'
|
||||
) {
|
||||
options = arg2;
|
||||
fn = arg3;
|
||||
} else if (
|
||||
arguments.length === 4 &&
|
||||
typeof arg2 === 'object' &&
|
||||
typeof arg3 === 'object' &&
|
||||
typeof arg4 === 'function'
|
||||
) {
|
||||
options = arg2;
|
||||
activeContext = arg3;
|
||||
fn = arg4;
|
||||
}
|
||||
|
||||
const parentContext = activeContext ?? api.context.active();
|
||||
const span = this.startSpan(name, options, parentContext);
|
||||
const contextWithSpanSet = api.trace.setSpan(parentContext, span);
|
||||
|
||||
if (fn) {
|
||||
return api.context.with(contextWithSpanSet, fn, undefined, span);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new Span or returns the default NoopSpan based on the sampling
|
||||
* decision.
|
||||
|
@ -89,7 +129,7 @@ export class Tracer implements api.Tracer {
|
|||
// make sampling decision
|
||||
const samplingResult = this._sampler.shouldSample(
|
||||
options.root
|
||||
? api.setSpanContext(context, api.INVALID_SPAN_CONTEXT)
|
||||
? api.trace.setSpanContext(context, api.INVALID_SPAN_CONTEXT)
|
||||
: context,
|
||||
traceId,
|
||||
name,
|
||||
|
@ -108,7 +148,7 @@ export class Tracer implements api.Tracer {
|
|||
return api.NOOP_TRACER.startSpan(
|
||||
name,
|
||||
options,
|
||||
api.setSpanContext(context, spanContext)
|
||||
api.trace.setSpanContext(context, spanContext)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -149,5 +189,5 @@ function getParent(
|
|||
context: api.Context
|
||||
): api.SpanContext | undefined {
|
||||
if (options.root) return undefined;
|
||||
return api.getSpanContext(context);
|
||||
return api.trace.getSpanContext(context);
|
||||
}
|
||||
|
|
|
@ -55,10 +55,10 @@ export class ConsoleSpanExporter implements SpanExporter {
|
|||
*/
|
||||
private _exportInfo(span: ReadableSpan) {
|
||||
return {
|
||||
traceId: span.spanContext.traceId,
|
||||
traceId: span.spanContext().traceId,
|
||||
parentId: span.parentSpanId,
|
||||
name: span.name,
|
||||
id: span.spanContext.spanId,
|
||||
id: span.spanContext().spanId,
|
||||
kind: span.kind,
|
||||
timestamp: hrTimeToMicroseconds(span.startTime),
|
||||
duration: hrTimeToMicroseconds(span.duration),
|
||||
|
|
|
@ -29,7 +29,7 @@ import { TimedEvent } from '../TimedEvent';
|
|||
export interface ReadableSpan {
|
||||
readonly name: string;
|
||||
readonly kind: SpanKind;
|
||||
readonly spanContext: SpanContext;
|
||||
readonly spanContext: () => SpanContext;
|
||||
readonly parentSpanId?: string;
|
||||
readonly startTime: HrTime;
|
||||
readonly endTime: HrTime;
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
|
||||
import {
|
||||
context,
|
||||
trace,
|
||||
SpanContext,
|
||||
TraceFlags,
|
||||
ROOT_CONTEXT,
|
||||
setSpan,
|
||||
setSpanContext,
|
||||
getSpan,
|
||||
TextMapPropagator,
|
||||
TextMapSetter,
|
||||
Context,
|
||||
|
@ -161,7 +159,7 @@ describe('BasicTracerProvider', () => {
|
|||
|
||||
let setGlobalPropagatorStub: sinon.SinonSpy<
|
||||
[TextMapPropagator],
|
||||
TextMapPropagator
|
||||
boolean
|
||||
>;
|
||||
let originalPropagators: string | number | undefined | string[];
|
||||
beforeEach(() => {
|
||||
|
@ -285,7 +283,7 @@ describe('BasicTracerProvider', () => {
|
|||
const span = tracer.startSpan('my-span', {});
|
||||
assert.ok(span);
|
||||
assert.ok(span instanceof Span);
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.ok(context.traceId.match(/[a-f0-9]{32}/));
|
||||
assert.ok(context.spanId.match(/[a-f0-9]{16}/));
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
|
@ -318,7 +316,7 @@ describe('BasicTracerProvider', () => {
|
|||
const span = tracer.startSpan(
|
||||
'my-span',
|
||||
{},
|
||||
setSpanContext(ROOT_CONTEXT, {
|
||||
trace.setSpanContext(ROOT_CONTEXT, {
|
||||
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
|
@ -326,7 +324,7 @@ describe('BasicTracerProvider', () => {
|
|||
})
|
||||
);
|
||||
assert.ok(span instanceof Span);
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.strictEqual(context.traceId, 'd4cda95b652f4a1592b449d5929fda1b');
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
assert.deepStrictEqual(context.traceState, state);
|
||||
|
@ -339,10 +337,10 @@ describe('BasicTracerProvider', () => {
|
|||
const childSpan = tracer.startSpan(
|
||||
'child-span',
|
||||
{},
|
||||
setSpan(ROOT_CONTEXT, span)
|
||||
trace.setSpan(ROOT_CONTEXT, span)
|
||||
);
|
||||
const context = childSpan.context();
|
||||
assert.strictEqual(context.traceId, span.context().traceId);
|
||||
const context = childSpan.spanContext();
|
||||
assert.strictEqual(context.traceId, span.spanContext().traceId);
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
span.end();
|
||||
childSpan.end();
|
||||
|
@ -355,10 +353,10 @@ describe('BasicTracerProvider', () => {
|
|||
const rootSpan = tracer.startSpan(
|
||||
'root-span',
|
||||
{ root: true },
|
||||
setSpan(ROOT_CONTEXT, span)
|
||||
trace.setSpan(ROOT_CONTEXT, span)
|
||||
);
|
||||
const context = rootSpan.context();
|
||||
assert.notStrictEqual(context.traceId, overrideParent.context().traceId);
|
||||
const context = rootSpan.spanContext();
|
||||
assert.notStrictEqual(context.traceId, overrideParent.spanContext().traceId);
|
||||
span.end();
|
||||
rootSpan.end();
|
||||
});
|
||||
|
@ -370,7 +368,7 @@ describe('BasicTracerProvider', () => {
|
|||
const span = tracer.startSpan(
|
||||
'my-span',
|
||||
{},
|
||||
setSpanContext(
|
||||
trace.setSpanContext(
|
||||
ROOT_CONTEXT,
|
||||
('invalid-parent' as unknown) as SpanContext
|
||||
)
|
||||
|
@ -384,14 +382,14 @@ describe('BasicTracerProvider', () => {
|
|||
const span = tracer.startSpan(
|
||||
'my-span',
|
||||
{},
|
||||
setSpanContext(ROOT_CONTEXT, {
|
||||
trace.setSpanContext(ROOT_CONTEXT, {
|
||||
traceId: '0',
|
||||
spanId: '0',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
})
|
||||
);
|
||||
assert.ok(span instanceof Span);
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.ok(context.traceId.match(/[a-f0-9]{32}/));
|
||||
assert.ok(context.spanId.match(/[a-f0-9]{16}/));
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
|
@ -404,7 +402,7 @@ describe('BasicTracerProvider', () => {
|
|||
}).getTracer('default');
|
||||
const span = tracer.startSpan('my-span');
|
||||
assert.ok(!span.isRecording());
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.ok(context.traceId.match(/[a-f0-9]{32}/));
|
||||
assert.ok(context.spanId.match(/[a-f0-9]{16}/));
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.NONE);
|
||||
|
@ -418,7 +416,7 @@ describe('BasicTracerProvider', () => {
|
|||
}).getTracer('default');
|
||||
const span = tracer.startSpan('my-span');
|
||||
assert.ok(span instanceof Span);
|
||||
assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(span.spanContext().traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(span.isRecording(), true);
|
||||
});
|
||||
|
||||
|
@ -434,8 +432,8 @@ describe('BasicTracerProvider', () => {
|
|||
it('should run context with NoopContextManager context manager', done => {
|
||||
const tracer = new BasicTracerProvider().getTracer('default');
|
||||
const span = tracer.startSpan('my-span');
|
||||
context.with(setSpan(context.active(), span), () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
context.with(trace.setSpan(context.active(), span), () => {
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
@ -504,10 +502,10 @@ describe('BasicTracerProvider', () => {
|
|||
const tracer = new BasicTracerProvider().getTracer('default');
|
||||
const span = tracer.startSpan('my-span');
|
||||
const fn = () => {
|
||||
assert.deepStrictEqual(getSpan(context.active()), undefined);
|
||||
assert.deepStrictEqual(trace.getSpan(context.active()), undefined);
|
||||
return done();
|
||||
};
|
||||
const patchedFn = context.bind(fn, setSpan(context.active(), span));
|
||||
const patchedFn = context.bind(fn, trace.setSpan(context.active(), span));
|
||||
return patchedFn();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
import {
|
||||
SpanStatusCode,
|
||||
Exception,
|
||||
LinkContext,
|
||||
ROOT_CONTEXT,
|
||||
SpanContext,
|
||||
SpanKind,
|
||||
|
@ -48,9 +47,10 @@ describe('Span', () => {
|
|||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
const linkContext: LinkContext = {
|
||||
const linkContext: SpanContext = {
|
||||
traceId: 'e4cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '7e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED
|
||||
};
|
||||
|
||||
it('should create a Span instance', () => {
|
||||
|
@ -179,7 +179,7 @@ describe('Span', () => {
|
|||
spanContext,
|
||||
SpanKind.CLIENT
|
||||
);
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.strictEqual(context.traceId, spanContext.traceId);
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
assert.strictEqual(context.traceState, undefined);
|
||||
|
@ -312,9 +312,10 @@ describe('Span', () => {
|
|||
spanId: '5e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED,
|
||||
};
|
||||
const linkContext: LinkContext = {
|
||||
const linkContext: SpanContext = {
|
||||
traceId: 'b3cda95b652f4a1592b449d5929fda1b',
|
||||
spanId: '6e0c63257de34c92',
|
||||
traceFlags: TraceFlags.SAMPLED
|
||||
};
|
||||
const attributes = { attr1: 'value', attr2: 123, attr3: true };
|
||||
const span = new Span(
|
||||
|
@ -380,7 +381,7 @@ describe('Span', () => {
|
|||
assert.strictEqual(span.name, 'my-span');
|
||||
assert.strictEqual(span.kind, SpanKind.INTERNAL);
|
||||
assert.strictEqual(span.parentSpanId, parentId);
|
||||
assert.strictEqual(span.spanContext.traceId, spanContext.traceId);
|
||||
assert.strictEqual(span.spanContext().traceId, spanContext.traceId);
|
||||
assert.deepStrictEqual(span.status, {
|
||||
code: SpanStatusCode.UNSET,
|
||||
});
|
||||
|
|
|
@ -19,9 +19,9 @@ import {
|
|||
ROOT_CONTEXT,
|
||||
Sampler,
|
||||
SamplingDecision,
|
||||
setSpanContext,
|
||||
SpanContext,
|
||||
TraceFlags,
|
||||
SpanContext,
|
||||
trace,
|
||||
} from '@opentelemetry/api';
|
||||
import {
|
||||
AlwaysOffSampler,
|
||||
|
@ -154,10 +154,10 @@ describe('Tracer', () => {
|
|||
const span = tracer.startSpan(
|
||||
'aSpan',
|
||||
undefined,
|
||||
setSpanContext(ROOT_CONTEXT, parent)
|
||||
trace.setSpanContext(ROOT_CONTEXT, parent)
|
||||
);
|
||||
assert.strictEqual((span as Span).parentSpanId, parent.spanId);
|
||||
assert.strictEqual(span.context().traceId, parent.traceId);
|
||||
assert.strictEqual(span.spanContext().traceId, parent.traceId);
|
||||
});
|
||||
|
||||
it('should not use spanId from invalid parent', () => {
|
||||
|
@ -174,7 +174,7 @@ describe('Tracer', () => {
|
|||
const span = tracer.startSpan(
|
||||
'aSpan',
|
||||
undefined,
|
||||
setSpanContext(ROOT_CONTEXT, parent)
|
||||
trace.setSpanContext(ROOT_CONTEXT, parent)
|
||||
);
|
||||
assert.strictEqual((span as Span).parentSpanId, undefined);
|
||||
});
|
||||
|
@ -188,7 +188,7 @@ describe('Tracer', () => {
|
|||
tracerProvider
|
||||
);
|
||||
const span = tracer.startSpan('my-span');
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
span.end();
|
||||
});
|
||||
|
@ -202,7 +202,7 @@ describe('Tracer', () => {
|
|||
tracerProvider
|
||||
);
|
||||
const span = tracer.startSpan('my-span');
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
|
||||
span.end();
|
||||
});
|
||||
|
@ -216,7 +216,7 @@ describe('Tracer', () => {
|
|||
tracerProvider
|
||||
);
|
||||
const span = tracer.startSpan('my-span');
|
||||
const context = span.context();
|
||||
const context = span.spanContext();
|
||||
assert.strictEqual(context.traceFlags, TraceFlags.NONE);
|
||||
span.end();
|
||||
});
|
||||
|
|
|
@ -79,7 +79,7 @@ describe('ConsoleSpanExporter', () => {
|
|||
|
||||
assert.ok(firstSpan.name === 'foo');
|
||||
assert.ok(firstEvent.name === 'foobar');
|
||||
assert.ok(consoleSpan.id === firstSpan.spanContext.spanId);
|
||||
assert.ok(consoleSpan.id === firstSpan.spanContext().spanId);
|
||||
assert.ok(keys === expectedKeys);
|
||||
|
||||
assert.ok(spyExport.calledOnce);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue