diff --git a/examples/basic-tracer-node/index.js b/examples/basic-tracer-node/index.js index fd046c0d45..b7092f339d 100644 --- a/examples/basic-tracer-node/index.js +++ b/examples/basic-tracer-node/index.js @@ -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. diff --git a/examples/basic-tracer-node/package.json b/examples/basic-tracer-node/package.json index 908b7a3cfa..596bf336f6 100644 --- a/examples/basic-tracer-node/package.json +++ b/examples/basic-tracer-node/package.json @@ -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" }, diff --git a/examples/collector-exporter-node/package.json b/examples/collector-exporter-node/package.json index f5b670a9fd..76f4c6747f 100644 --- a/examples/collector-exporter-node/package.json +++ b/examples/collector-exporter-node/package.json @@ -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", diff --git a/examples/collector-exporter-node/tracing.js b/examples/collector-exporter-node/tracing.js index 96c03db64d..5f0bd39e17 100644 --- a/examples/collector-exporter-node/tracing.js +++ b/examples/collector-exporter-node/tracing.js @@ -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. diff --git a/examples/grpc-js/client.js b/examples/grpc-js/client.js index 48820ee136..471f6ff94d 100644 --- a/examples/grpc-js/client.js +++ b/examples/grpc-js/client.js @@ -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(), diff --git a/examples/grpc-js/package.json b/examples/grpc-js/package.json index 7574d16972..62420840b5 100644 --- a/examples/grpc-js/package.json +++ b/examples/grpc-js/package.json @@ -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", diff --git a/examples/grpc-js/server.js b/examples/grpc-js/server.js index 90b023815a..e76a112288 100644 --- a/examples/grpc-js/server.js +++ b/examples/grpc-js/server.js @@ -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' }, diff --git a/examples/grpc/client.js b/examples/grpc/client.js index 5bb4b630aa..56825a906b 100644 --- a/examples/grpc/client.js +++ b/examples/grpc/client.js @@ -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(), diff --git a/examples/grpc/package.json b/examples/grpc/package.json index b2379391f4..15a264f543 100644 --- a/examples/grpc/package.json +++ b/examples/grpc/package.json @@ -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", diff --git a/examples/grpc/server.js b/examples/grpc/server.js index 40db771365..7422f63edb 100644 --- a/examples/grpc/server.js +++ b/examples/grpc/server.js @@ -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 diff --git a/examples/http/client.js b/examples/http/client.js index a27ba0355e..79dcc99a5a 100644 --- a/examples/http/client.js +++ b/examples/http/client.js @@ -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, diff --git a/examples/http/package.json b/examples/http/package.json index 0527162a8c..ffe53eefd8 100644 --- a/examples/http/package.json +++ b/examples/http/package.json @@ -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", diff --git a/examples/http/server.js b/examples/http/server.js index 604f688f84..b8d4f1e003 100644 --- a/examples/http/server.js +++ b/examples/http/server.js @@ -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' }, diff --git a/examples/https/client.js b/examples/https/client.js index d842becef3..4befda7955 100644 --- a/examples/https/client.js +++ b/examples/https/client.js @@ -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, diff --git a/examples/https/package.json b/examples/https/package.json index 8826242b54..396a7301ef 100644 --- a/examples/https/package.json +++ b/examples/https/package.json @@ -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", diff --git a/examples/https/server.js b/examples/https/server.js index d4a2357368..73fc6d3535 100644 --- a/examples/https/server.js +++ b/examples/https/server.js @@ -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' }, diff --git a/examples/opentracing-shim/server.js b/examples/opentracing-shim/server.js index a21f93a149..cf54c646fb 100644 --- a/examples/opentracing-shim/server.js +++ b/examples/opentracing-shim/server.js @@ -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(); diff --git a/examples/tracer-web/examples/fetch/index.js b/examples/tracer-web/examples/fetch/index.js index 97f9910d2d..10a7c5f2a5 100644 --- a/examples/tracer-web/examples/fetch/index.js +++ b/examples/tracer-web/examples/fetch/index.js @@ -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(); }); }); diff --git a/examples/tracer-web/examples/xml-http-request/index.js b/examples/tracer-web/examples/xml-http-request/index.js index c3990efe7a..0c2b0d8a5e 100644 --- a/examples/tracer-web/examples/xml-http-request/index.js +++ b/examples/tracer-web/examples/xml-http-request/index.js @@ -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(); }); }); diff --git a/examples/tracer-web/package.json b/examples/tracer-web/package.json index dd06ea5474..40d786daa2 100644 --- a/examples/tracer-web/package.json +++ b/examples/tracer-web/package.json @@ -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", diff --git a/examples/tracer-web/webpack.config.js b/examples/tracer-web/webpack.config.js index e47148709e..f316e959a0 100644 --- a/examples/tracer-web/webpack.config.js +++ b/examples/tracer-web/webpack.config.js @@ -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', diff --git a/integration-tests/propagation-validation-server/package.json b/integration-tests/propagation-validation-server/package.json index 003b8afc23..9370b68f8b 100644 --- a/integration-tests/propagation-validation-server/package.json +++ b/integration-tests/propagation-validation-server/package.json @@ -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" } } diff --git a/integration-tests/propagation-validation-server/validation-server.js b/integration-tests/propagation-validation-server/validation-server.js index 2c327cacb8..3587669cc5 100644 --- a/integration-tests/propagation-validation-server/validation-server.js +++ b/integration-tests/propagation-validation-server/validation-server.js @@ -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 diff --git a/packages/opentelemetry-api-metrics/package.json b/packages/opentelemetry-api-metrics/package.json index 27a71227d9..f7e84412eb 100644 --- a/packages/opentelemetry-api-metrics/package.json +++ b/packages/opentelemetry-api-metrics/package.json @@ -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", diff --git a/packages/opentelemetry-context-async-hooks/package.json b/packages/opentelemetry-context-async-hooks/package.json index 7cca3257e2..6578681517 100644 --- a/packages/opentelemetry-context-async-hooks/package.json +++ b/packages/opentelemetry-context-async-hooks/package.json @@ -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" } } diff --git a/packages/opentelemetry-context-zone-peer-dep/README.md b/packages/opentelemetry-context-zone-peer-dep/README.md index e7c0294ea7..b167b31a0a 100644 --- a/packages/opentelemetry-context-zone-peer-dep/README.md +++ b/packages/opentelemetry-context-zone-peer-dep/README.md @@ -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); }); ``` diff --git a/packages/opentelemetry-context-zone-peer-dep/package.json b/packages/opentelemetry-context-zone-peer-dep/package.json index c2ad6c8fb2..25e9387588 100644 --- a/packages/opentelemetry-context-zone-peer-dep/package.json +++ b/packages/opentelemetry-context-zone-peer-dep/package.json @@ -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 diff --git a/packages/opentelemetry-context-zone/README.md b/packages/opentelemetry-context-zone/README.md index 09f30edf68..8668fafe28 100644 --- a/packages/opentelemetry-context-zone/README.md +++ b/packages/opentelemetry-context-zone/README.md @@ -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); }); ``` diff --git a/packages/opentelemetry-core/package.json b/packages/opentelemetry-core/package.json index b20b593560..cd8656626e 100644 --- a/packages/opentelemetry-core/package.json +++ b/packages/opentelemetry-core/package.json @@ -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", diff --git a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts index 770df35be6..3cd023c719 100644 --- a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts +++ b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts @@ -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[] { diff --git a/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts b/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts index ff55a4da87..53d3bf11fb 100644 --- a/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts +++ b/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts @@ -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[] { diff --git a/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts b/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts index a20f9ba181..6cd10b1484 100644 --- a/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts +++ b/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts @@ -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( diff --git a/packages/opentelemetry-core/test/baggage/HttpBaggagePropagator.test.ts b/packages/opentelemetry-core/test/baggage/HttpBaggagePropagator.test.ts index 04aace011a..679d6f48d2 100644 --- a/packages/opentelemetry-core/test/baggage/HttpBaggagePropagator.test.ts +++ b/packages/opentelemetry-core/test/baggage/HttpBaggagePropagator.test.ts @@ -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, diff --git a/packages/opentelemetry-core/test/propagation/composite.test.ts b/packages/opentelemetry-core/test/propagation/composite.test.ts index 6448ddbae2..1e5b6d989a 100644 --- a/packages/opentelemetry-core/test/propagation/composite.test.ts +++ b/packages/opentelemetry-core/test/propagation/composite.test.ts @@ -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): void { - carrier['dummy'] = getSpanContext(context); + carrier['dummy'] = trace.getSpanContext(context); } extract(context: Context, carrier: any, getter: TextMapGetter): 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) ); diff --git a/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts b/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts index 5199aed0bb..0ccd526e6f 100644 --- a/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts +++ b/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts @@ -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) ); diff --git a/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts b/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts index 4394227de4..828a32fa3e 100644 --- a/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts +++ b/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts @@ -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, diff --git a/packages/opentelemetry-exporter-collector-grpc/package.json b/packages/opentelemetry-exporter-collector-grpc/package.json index a259e72bf1..2c05c1d97b 100644 --- a/packages/opentelemetry-exporter-collector-grpc/package.json +++ b/packages/opentelemetry-exporter-collector-grpc/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts index 147fb1c236..94591f5a2f 100644 --- a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts @@ -111,10 +111,12 @@ export function mockValueRecorder(): metrics.Metric 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' }, }, diff --git a/packages/opentelemetry-exporter-collector-proto/package.json b/packages/opentelemetry-exporter-collector-proto/package.json index a3f606d859..276557a17d 100644 --- a/packages/opentelemetry-exporter-collector-proto/package.json +++ b/packages/opentelemetry-exporter-collector-proto/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-collector-proto/test/helper.ts b/packages/opentelemetry-exporter-collector-proto/test/helper.ts index 83a98ca10d..7c35bb8b53 100644 --- a/packages/opentelemetry-exporter-collector-proto/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-proto/test/helper.ts @@ -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' }, }, diff --git a/packages/opentelemetry-exporter-collector/package.json b/packages/opentelemetry-exporter-collector/package.json index 1e743a9af7..b400c13000 100644 --- a/packages/opentelemetry-exporter-collector/package.json +++ b/packages/opentelemetry-exporter-collector/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index ee62762159..37770ef759 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -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), diff --git a/packages/opentelemetry-exporter-collector/test/common/transform.test.ts b/packages/opentelemetry-exporter-collector/test/common/transform.test.ts index f212a7774a..b67eae84ea 100644 --- a/packages/opentelemetry-exporter-collector/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-collector/test/common/transform.test.ts @@ -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 { diff --git a/packages/opentelemetry-exporter-collector/test/helper.ts b/packages/opentelemetry-exporter-collector/test/helper.ts index f4d28a035a..dde640298e 100644 --- a/packages/opentelemetry-exporter-collector/test/helper.ts +++ b/packages/opentelemetry-exporter-collector/test/helper.ts @@ -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], diff --git a/packages/opentelemetry-exporter-jaeger/package.json b/packages/opentelemetry-exporter-jaeger/package.json index 7399629051..b0bfd07521 100644 --- a/packages/opentelemetry-exporter-jaeger/package.json +++ b/packages/opentelemetry-exporter-jaeger/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-jaeger/src/transform.ts b/packages/opentelemetry-exporter-jaeger/src/transform.ts index bb3ea5e5f1..0d7a83062e 100644 --- a/packages/opentelemetry-exporter-jaeger/src/transform.ts +++ b/packages/opentelemetry-exporter-jaeger/src/transform.ts @@ -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, diff --git a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts index a58a41b628..afa0605497 100644 --- a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts @@ -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], diff --git a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts index da4fc5473d..209b37c9b3 100644 --- a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts @@ -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, diff --git a/packages/opentelemetry-exporter-prometheus/package.json b/packages/opentelemetry-exporter-prometheus/package.json index 8477905ad1..cb3157afca 100644 --- a/packages/opentelemetry-exporter-prometheus/package.json +++ b/packages/opentelemetry-exporter-prometheus/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index d485b87b62..b6ee71417e 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index 4f8e3145c6..3e34301f85 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -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), diff --git a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts index 4e47d0c095..e1336ed151 100644 --- a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts @@ -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, }); }) ); diff --git a/packages/opentelemetry-exporter-zipkin/test/helper.ts b/packages/opentelemetry-exporter-zipkin/test/helper.ts index 837ca39118..2ab7c4a3c3 100644 --- a/packages/opentelemetry-exporter-zipkin/test/helper.ts +++ b/packages/opentelemetry-exporter-zipkin/test/helper.ts @@ -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 }` ); }); } diff --git a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts index 0dbe5908aa..846e30ab06 100644 --- a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts @@ -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], diff --git a/packages/opentelemetry-instrumentation-fetch/package.json b/packages/opentelemetry-instrumentation-fetch/package.json index 0a1090ed83..d374509565 100644 --- a/packages/opentelemetry-instrumentation-fetch/package.json +++ b/packages/opentelemetry-instrumentation-fetch/package.json @@ -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", diff --git a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts index ec6cae7cf4..ef12407ff9 100644 --- a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts +++ b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts @@ -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++; diff --git a/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts b/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts index 51b05134f3..017aea8056 100644 --- a/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts +++ b/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts @@ -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' ); }); diff --git a/packages/opentelemetry-instrumentation-grpc/package.json b/packages/opentelemetry-instrumentation-grpc/package.json index 392911764c..34f9e5d4cd 100644 --- a/packages/opentelemetry-instrumentation-grpc/package.json +++ b/packages/opentelemetry-instrumentation-grpc/package.json @@ -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", diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts index 1b098c17cc..9db0311667 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts @@ -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) ); }; diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts index 89ce5db3de..84deb7b228 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts @@ -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, diff --git a/packages/opentelemetry-instrumentation-grpc/test/helper.ts b/packages/opentelemetry-instrumentation-grpc/test/helper.ts index 1c71e49430..62cab27167 100644 --- a/packages/opentelemetry-instrumentation-grpc/test/helper.ts +++ b/packages/opentelemetry-instrumentation-grpc/test/helper.ts @@ -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 ); }); diff --git a/packages/opentelemetry-instrumentation-grpc/test/utils/assertionUtils.ts b/packages/opentelemetry-instrumentation-grpc/test/utils/assertionUtils.ts index 90a05ec97f..a0b863b03e 100644 --- a/packages/opentelemetry-instrumentation-grpc/test/utils/assertionUtils.ts +++ b/packages/opentelemetry-instrumentation-grpc/test/utils/assertionUtils.ts @@ -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( diff --git a/packages/opentelemetry-instrumentation-http/package.json b/packages/opentelemetry-instrumentation-http/package.json index a81677fb74..34f3b22af0 100644 --- a/packages/opentelemetry-instrumentation-http/package.json +++ b/packages/opentelemetry-instrumentation-http/package.json @@ -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", diff --git a/packages/opentelemetry-instrumentation-http/src/http.ts b/packages/opentelemetry-instrumentation-http/src/http.ts index 008eac92bc..cee10867eb 100644 --- a/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/packages/opentelemetry-instrumentation-http/src/http.ts @@ -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 { 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 { 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 { : 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); diff --git a/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts index 2361b26756..4f34269347 100644 --- a/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts @@ -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 => { diff --git a/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts index fe473f408f..3b9fa505d1 100644 --- a/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts @@ -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(); diff --git a/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts b/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts index 7ce15eaf7f..4dbda67c16 100644 --- a/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts +++ b/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts @@ -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; diff --git a/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts b/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts index 97af42abee..91263eb945 100644 --- a/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts +++ b/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts @@ -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, diff --git a/packages/opentelemetry-instrumentation-xml-http-request/package.json b/packages/opentelemetry-instrumentation-xml-http-request/package.json index 603e2e52f2..00bc0b247f 100644 --- a/packages/opentelemetry-instrumentation-xml-http-request/package.json +++ b/packages/opentelemetry-instrumentation-xml-http-request/package.json @@ -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", diff --git a/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts b/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts index fb7274cdce..0cca5535c6 100644 --- a/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts +++ b/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts @@ -139,7 +139,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase { + 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 { plugin._tasksCount++; xhrMem.sendStartTime = hrTime(); diff --git a/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts b/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts index fa8bb22469..69ec33a926 100644 --- a/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts +++ b/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts @@ -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; diff --git a/packages/opentelemetry-instrumentation/package.json b/packages/opentelemetry-instrumentation/package.json index 511cda4985..4e020184e7 100644 --- a/packages/opentelemetry-instrumentation/package.json +++ b/packages/opentelemetry-instrumentation/package.json @@ -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", diff --git a/packages/opentelemetry-metrics/package.json b/packages/opentelemetry-metrics/package.json index 6978335b41..eb4da1f628 100644 --- a/packages/opentelemetry-metrics/package.json +++ b/packages/opentelemetry-metrics/package.json @@ -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", diff --git a/packages/opentelemetry-node/package.json b/packages/opentelemetry-node/package.json index 5f31927896..7d7be4daf4 100644 --- a/packages/opentelemetry-node/package.json +++ b/packages/opentelemetry-node/package.json @@ -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", diff --git a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts index 24d1d0e82c..4635fbf559 100644 --- a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts +++ b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts @@ -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(); }); }); diff --git a/packages/opentelemetry-propagator-b3/package.json b/packages/opentelemetry-propagator-b3/package.json index 20d1cb9368..3218776db9 100644 --- a/packages/opentelemetry-propagator-b3/package.json +++ b/packages/opentelemetry-propagator-b3/package.json @@ -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", diff --git a/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts b/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts index 4fbd40827b..17b2a3859d 100644 --- a/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts @@ -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, diff --git a/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts b/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts index a0a83064fa..6a26a93265 100644 --- a/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts @@ -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, diff --git a/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts index d4c828af27..a314385b57 100644 --- a/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts @@ -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', diff --git a/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts index b86ea6e82e..6efec8336a 100644 --- a/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts @@ -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', diff --git a/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts index 65f9fda675..231a111ff4 100644 --- a/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts @@ -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); }); }); diff --git a/packages/opentelemetry-propagator-jaeger/package.json b/packages/opentelemetry-propagator-jaeger/package.json index 156efa08fc..96ae171327 100644 --- a/packages/opentelemetry-propagator-jaeger/package.json +++ b/packages/opentelemetry-propagator-jaeger/package.json @@ -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" diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts index 2c713409c3..252dc39fb5 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts @@ -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; } diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts index 13721f862e..93836c84c9 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts @@ -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) ); diff --git a/packages/opentelemetry-resource-detector-aws/package.json b/packages/opentelemetry-resource-detector-aws/package.json index 0c436485fd..1a774da5eb 100644 --- a/packages/opentelemetry-resource-detector-aws/package.json +++ b/packages/opentelemetry-resource-detector-aws/package.json @@ -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", diff --git a/packages/opentelemetry-resource-detector-gcp/package.json b/packages/opentelemetry-resource-detector-gcp/package.json index abb647da0f..57486e7130 100644 --- a/packages/opentelemetry-resource-detector-gcp/package.json +++ b/packages/opentelemetry-resource-detector-gcp/package.json @@ -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", diff --git a/packages/opentelemetry-resources/package.json b/packages/opentelemetry-resources/package.json index d8ae074e6e..c566fa2a28 100644 --- a/packages/opentelemetry-resources/package.json +++ b/packages/opentelemetry-resources/package.json @@ -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", diff --git a/packages/opentelemetry-sdk-node/package.json b/packages/opentelemetry-sdk-node/package.json index aaa3066ea5..2840d17503 100644 --- a/packages/opentelemetry-sdk-node/package.json +++ b/packages/opentelemetry-sdk-node/package.json @@ -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", diff --git a/packages/opentelemetry-shim-opentracing/package.json b/packages/opentelemetry-shim-opentracing/package.json index 2a3f2b1ee2..24e94538aa 100644 --- a/packages/opentelemetry-shim-opentracing/package.json +++ b/packages/opentelemetry-shim-opentracing/package.json @@ -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", diff --git a/packages/opentelemetry-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index 0fedcb5e01..18632de9d3 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -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; } diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index 47d197c877..280e78fd00 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -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); diff --git a/packages/opentelemetry-tracing/package.json b/packages/opentelemetry-tracing/package.json index f67ef5f0cb..2e19249b75 100644 --- a/packages/opentelemetry-tracing/package.json +++ b/packages/opentelemetry-tracing/package.json @@ -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", diff --git a/packages/opentelemetry-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index d7a18fbe2e..8ffad7ab0a 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -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; diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index e574f123de..8bd24bf7bf 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -54,6 +54,46 @@ export class Tracer implements api.Tracer { this.instrumentationLibrary = instrumentationLibrary; } + startActiveSpan ReturnType>( + name: string, + arg2: F | api.SpanOptions, + arg3?: F | api.Context, + arg4?: F + ): ReturnType | 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); } diff --git a/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts index 8c481f62bf..60f803c5d0 100644 --- a/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts +++ b/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts @@ -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), diff --git a/packages/opentelemetry-tracing/src/export/ReadableSpan.ts b/packages/opentelemetry-tracing/src/export/ReadableSpan.ts index 381de674ff..8552134a56 100644 --- a/packages/opentelemetry-tracing/src/export/ReadableSpan.ts +++ b/packages/opentelemetry-tracing/src/export/ReadableSpan.ts @@ -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; diff --git a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts index 06bdb2d6e0..906fb79e9d 100644 --- a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts +++ b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts @@ -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(); }); }); diff --git a/packages/opentelemetry-tracing/test/Span.test.ts b/packages/opentelemetry-tracing/test/Span.test.ts index 75631fa5c3..ce65b6c8d0 100644 --- a/packages/opentelemetry-tracing/test/Span.test.ts +++ b/packages/opentelemetry-tracing/test/Span.test.ts @@ -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, }); diff --git a/packages/opentelemetry-tracing/test/Tracer.test.ts b/packages/opentelemetry-tracing/test/Tracer.test.ts index 7a69c4dbdb..08b2b66c79 100644 --- a/packages/opentelemetry-tracing/test/Tracer.test.ts +++ b/packages/opentelemetry-tracing/test/Tracer.test.ts @@ -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(); }); diff --git a/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts index 1370bdbec3..674efb53d6 100644 --- a/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts @@ -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); diff --git a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts index 3f8c916768..88be64a67d 100644 --- a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts @@ -20,7 +20,7 @@ import { SimpleSpanProcessor, BasicTracerProvider, } from '../../src'; -import { context, setSpan } from '@opentelemetry/api'; +import { context, trace } from '@opentelemetry/api'; import { ExportResult, ExportResultCode } from '@opentelemetry/core'; describe('InMemorySpanExporter', () => { @@ -37,10 +37,10 @@ describe('InMemorySpanExporter', () => { const root = provider.getTracer('default').startSpan('root'); const child = provider .getTracer('default') - .startSpan('child', {}, setSpan(context.active(), root)); + .startSpan('child', {}, trace.setSpan(context.active(), root)); const grandChild = provider .getTracer('default') - .startSpan('grand-child', {}, setSpan(context.active(), child)); + .startSpan('grand-child', {}, trace.setSpan(context.active(), child)); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); grandChild.end(); @@ -54,10 +54,10 @@ describe('InMemorySpanExporter', () => { assert.strictEqual(span1.name, 'grand-child'); assert.strictEqual(span2.name, 'child'); assert.strictEqual(span3.name, 'root'); - assert.strictEqual(span1.spanContext.traceId, span2.spanContext.traceId); - assert.strictEqual(span2.spanContext.traceId, span3.spanContext.traceId); - assert.strictEqual(span1.parentSpanId, span2.spanContext.spanId); - assert.strictEqual(span2.parentSpanId, span3.spanContext.spanId); + assert.strictEqual(span1.spanContext().traceId, span2.spanContext().traceId); + assert.strictEqual(span2.spanContext().traceId, span3.spanContext().traceId); + assert.strictEqual(span1.parentSpanId, span2.spanContext().spanId); + assert.strictEqual(span2.parentSpanId, span3.spanContext().spanId); }); it('should shutdown the exporter', () => { @@ -65,7 +65,7 @@ describe('InMemorySpanExporter', () => { provider .getTracer('default') - .startSpan('child', {}, setSpan(context.active(), root)) + .startSpan('child', {}, trace.setSpan(context.active(), root)) .end(); root.end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 2); @@ -75,7 +75,7 @@ describe('InMemorySpanExporter', () => { // after shutdown no new spans are accepted provider .getTracer('default') - .startSpan('child1', {}, setSpan(context.active(), root)) + .startSpan('child1', {}, trace.setSpan(context.active(), root)) .end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); }); diff --git a/packages/opentelemetry-web/package.json b/packages/opentelemetry-web/package.json index 3e5d84a856..57dadf931c 100644 --- a/packages/opentelemetry-web/package.json +++ b/packages/opentelemetry-web/package.json @@ -46,7 +46,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/resources": "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", diff --git a/packages/opentelemetry-web/test/WebTracerProvider.test.ts b/packages/opentelemetry-web/test/WebTracerProvider.test.ts index a73845bfff..18462a14a6 100644 --- a/packages/opentelemetry-web/test/WebTracerProvider.test.ts +++ b/packages/opentelemetry-web/test/WebTracerProvider.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { context, getSpan, setSpan, ContextManager } from '@opentelemetry/api'; +import { context, ContextManager, trace } from '@opentelemetry/api'; import { ZoneContextManager } from '@opentelemetry/context-zone'; import { B3Propagator } from '@opentelemetry/propagator-b3'; import { Resource } from '@opentelemetry/resources'; @@ -91,9 +91,9 @@ describe('WebTracerProvider', () => { const rootSpan = webTracerWithZone.startSpan('rootSpan'); - context.with(setSpan(context.active(), rootSpan), () => { + context.with(trace.setSpan(context.active(), rootSpan), () => { assert.ok( - getSpan(context.active()) === rootSpan, + trace.getSpan(context.active()) === rootSpan, 'Current span is rootSpan' ); const concurrentSpan1 = webTracerWithZone.startSpan( @@ -103,19 +103,19 @@ describe('WebTracerProvider', () => { 'concurrentSpan2' ); - context.with(setSpan(context.active(), concurrentSpan1), () => { + context.with(trace.setSpan(context.active(), concurrentSpan1), () => { setTimeout(() => { assert.ok( - getSpan(context.active()) === concurrentSpan1, + trace.getSpan(context.active()) === concurrentSpan1, 'Current span is concurrentSpan1' ); }, 10); }); - context.with(setSpan(context.active(), concurrentSpan2), () => { + context.with(trace.setSpan(context.active(), concurrentSpan2), () => { setTimeout(() => { assert.ok( - getSpan(context.active()) === concurrentSpan2, + trace.getSpan(context.active()) === concurrentSpan2, 'Current span is concurrentSpan2' ); done();