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: update http example #3651

Merged
merged 6 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/http/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions examples/http/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions examples/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"selenium-tests",
"examples/otlp-exporter-node",
"examples/opentelemetry-web",
"examples/http",
"examples/https"
]
}