Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrading to api ver. 0.20.0 #2225

Merged
merged 6 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-tracer-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/collector-exporter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/collector-exporter-node/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc-js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc-js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/http/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion examples/https/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/https/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/https/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion examples/opentracing-shim/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 5 additions & 7 deletions examples/tracer-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
});
});
Expand Down
8 changes: 4 additions & 4 deletions examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
});
});
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/tracer-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-api-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-context-async-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -53,6 +53,6 @@
"typescript": "4.2.4"
},
"peerDependencies": {
"@opentelemetry/api": "^1.0.0-rc.0"
"@opentelemetry/api": "^0.20.0"
}
}
18 changes: 9 additions & 9 deletions packages/opentelemetry-context-zone-peer-dep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
});

```
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-context-zone-peer-dep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions packages/opentelemetry-context-zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
});

```
Expand Down