Skip to content

Commit 4a4484a

Browse files
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 <[email protected]>
1 parent 494efff commit 4a4484a

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
2727

2828
### :books: (Refine Doc)
2929

30+
* chore: update http example [#3651](https://github.com/open-telemetry/opentelemetry-js/pull/3651) @JamieDanielson
31+
3032
### :house: (Internal)
3133

3234
* fix(sdk-metrics): fix flaky LastValueAggregator test by using fake timer [#3587](https://github.com/open-telemetry/opentelemetry-js/pull/3587) @pichlermarc

examples/http/client.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ function makeRequest() {
99
// span corresponds to outgoing requests. Here, we have manually created
1010
// the span, which is created to track work that happens outside of the
1111
// request lifecycle entirely.
12-
const span = tracer.startSpan('makeRequest');
13-
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
12+
tracer.startActiveSpan('makeRequest', (span) => {
1413
http.get({
1514
host: 'localhost',
1615
port: 8080,

examples/http/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "http-example",
33
"private": true,
4-
"version": "0.25.0",
4+
"version": "0.35.1",
55
"description": "Example of HTTP integration with OpenTelemetry",
66
"main": "index.js",
77
"scripts": {
@@ -28,15 +28,15 @@
2828
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
2929
},
3030
"dependencies": {
31-
"@opentelemetry/api": "^1.0.2",
32-
"@opentelemetry/exporter-jaeger": "0.25.0",
33-
"@opentelemetry/exporter-zipkin": "0.25.0",
34-
"@opentelemetry/instrumentation": "0.25.0",
35-
"@opentelemetry/instrumentation-http": "0.25.0",
36-
"@opentelemetry/resources": "0.25.0",
37-
"@opentelemetry/semantic-conventions": "0.25.0",
38-
"@opentelemetry/sdk-trace-node": "0.25.0",
39-
"@opentelemetry/sdk-trace-base": "0.25.0"
31+
"@opentelemetry/api": "^1.3.0",
32+
"@opentelemetry/exporter-jaeger": "1.9.1",
33+
"@opentelemetry/exporter-zipkin": "1.9.1",
34+
"@opentelemetry/instrumentation": "0.35.1",
35+
"@opentelemetry/instrumentation-http": "0.35.1",
36+
"@opentelemetry/resources": "1.9.1",
37+
"@opentelemetry/semantic-conventions": "1.9.1",
38+
"@opentelemetry/sdk-trace-node": "1.9.1",
39+
"@opentelemetry/sdk-trace-base": "1.9.1"
4040
},
4141
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/http",
4242
"devDependencies": {

examples/http/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ function startServer(port) {
1919

2020
/** A function which handles requests and send response. */
2121
function handleRequest(request, response) {
22-
const currentSpan = api.trace.getSpan(api.context.active());
22+
const currentSpan = api.trace.getActiveSpan();
2323
// display traceid in the terminal
24-
console.log(`traceid: ${currentSpan.spanContext().traceId}`);
24+
const traceId = currentSpan.spanContext().traceId;
25+
console.log(`traceId: ${traceId}`);
2526
const span = tracer.startSpan('handleRequest', {
2627
kind: 1, // server
2728
attributes: { key: 'value' },

lerna.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"selenium-tests",
1212
"examples/otlp-exporter-node",
1313
"examples/opentelemetry-web",
14+
"examples/http",
1415
"examples/https"
1516
]
1617
}

0 commit comments

Comments
 (0)