From 4a4484a910201466121ed45fa12566737f6ac19d Mon Sep 17 00:00:00 2001 From: Jamie Danielson Date: Thu, 2 Mar 2023 09:36:24 -0500 Subject: [PATCH] chore: update http example (#3651) * update versions in http example * use newer active span methods for http example * fix(changelog): add changelog entry * Add http example to lerna --------- Co-authored-by: Daniel Dyla --- CHANGELOG.md | 2 ++ examples/http/client.js | 3 +-- examples/http/package.json | 20 ++++++++++---------- examples/http/server.js | 5 +++-- lerna.json | 1 + 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5014e7737..6f2bae09b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :books: (Refine Doc) +* chore: update http example [#3651](https://github.com/open-telemetry/opentelemetry-js/pull/3651) @JamieDanielson + ### :house: (Internal) * fix(sdk-metrics): fix flaky LastValueAggregator test by using fake timer [#3587](https://github.com/open-telemetry/opentelemetry-js/pull/3587) @pichlermarc diff --git a/examples/http/client.js b/examples/http/client.js index 40babbda89..168d433922 100644 --- a/examples/http/client.js +++ b/examples/http/client.js @@ -9,8 +9,7 @@ function makeRequest() { // span corresponds to outgoing requests. Here, we have manually created // 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.trace.setSpan(api.context.active(), span), () => { + tracer.startActiveSpan('makeRequest', (span) => { http.get({ host: 'localhost', port: 8080, diff --git a/examples/http/package.json b/examples/http/package.json index 490f9dba75..f10a5992dc 100644 --- a/examples/http/package.json +++ b/examples/http/package.json @@ -1,7 +1,7 @@ { "name": "http-example", "private": true, - "version": "0.25.0", + "version": "0.35.1", "description": "Example of HTTP integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,15 +28,15 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^1.0.2", - "@opentelemetry/exporter-jaeger": "0.25.0", - "@opentelemetry/exporter-zipkin": "0.25.0", - "@opentelemetry/instrumentation": "0.25.0", - "@opentelemetry/instrumentation-http": "0.25.0", - "@opentelemetry/resources": "0.25.0", - "@opentelemetry/semantic-conventions": "0.25.0", - "@opentelemetry/sdk-trace-node": "0.25.0", - "@opentelemetry/sdk-trace-base": "0.25.0" + "@opentelemetry/api": "^1.3.0", + "@opentelemetry/exporter-jaeger": "1.9.1", + "@opentelemetry/exporter-zipkin": "1.9.1", + "@opentelemetry/instrumentation": "0.35.1", + "@opentelemetry/instrumentation-http": "0.35.1", + "@opentelemetry/resources": "1.9.1", + "@opentelemetry/semantic-conventions": "1.9.1", + "@opentelemetry/sdk-trace-node": "1.9.1", + "@opentelemetry/sdk-trace-base": "1.9.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/http", "devDependencies": { diff --git a/examples/http/server.js b/examples/http/server.js index 1c11f60323..ea65858b52 100644 --- a/examples/http/server.js +++ b/examples/http/server.js @@ -19,9 +19,10 @@ function startServer(port) { /** A function which handles requests and send response. */ function handleRequest(request, response) { - const currentSpan = api.trace.getSpan(api.context.active()); + const currentSpan = api.trace.getActiveSpan(); // display traceid in the terminal - console.log(`traceid: ${currentSpan.spanContext().traceId}`); + const traceId = currentSpan.spanContext().traceId; + console.log(`traceId: ${traceId}`); const span = tracer.startSpan('handleRequest', { kind: 1, // server attributes: { key: 'value' }, diff --git a/lerna.json b/lerna.json index d97ab02a62..6eba3f4874 100644 --- a/lerna.json +++ b/lerna.json @@ -11,6 +11,7 @@ "selenium-tests", "examples/otlp-exporter-node", "examples/opentelemetry-web", + "examples/http", "examples/https" ] }