Skip to content

Commit 3156c94

Browse files
jessitrontrentmJamieDanielsonpichlermarc
authored
chore: Update deprecations in instrumentation-express/examples (#1842)
* chore: Update express example package.json since it moved repos This must have moved into contrib a while back * docs: Modify the install command so that the example runs Without this, 'npm install' now depends on directories higher than this one. It does not create a node_modules and then ts-node does not work. Looks like the use of workspaces at the repository root interferes with this example, but this change to the install command gets around that. * chore: Update instrumentation-express example otel packages to the latest * chore: Update all deprecations in tracer.ts Jaeger accepts OTLP now, so the OtlpTraceExporter just works * update package-lock for (hopefully) desired package.json dep updates * sync package-lock.json * sync package-lock.json again (dropping dev:true from '@types/express', why I am not sure) * add setup script and alternative install * sync package-lock.json * bump the express example's dep to the instr-express version in the repo I also had to manually remove this (vestigial?) entry in package-lock.json that was breaking 'npm install'. * signing off on changes Signed-off-by: Jamie Danielson <[email protected]> --------- Signed-off-by: Jamie Danielson <[email protected]> Co-authored-by: Trent Mick <[email protected]> Co-authored-by: Jamie Danielson <[email protected]> Co-authored-by: Marc Pichler <[email protected]> Co-authored-by: Jamie Danielson <[email protected]>
1 parent c8bebc7 commit 3156c94

File tree

4 files changed

+46
-191
lines changed

4 files changed

+46
-191
lines changed

package-lock.json

Lines changed: 19 additions & 167 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/node/opentelemetry-instrumentation-express/examples/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ shows key aspects of tracing such as
1313
## Installation
1414

1515
```sh
16-
# from this directory
17-
npm install
16+
# from this directory, install all necessary dependencies from the workspace
17+
npm run setup
18+
19+
# OR alternatively, install dependencies from npm as a standalone example app
20+
npm install --workspaces=false
1821
```
1922

2023
Setup [Zipkin Tracing](https://zipkin.io/pages/quickstart.html)

plugins/node/opentelemetry-instrumentation-express/examples/package.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
22
"name": "express-example",
33
"private": true,
4-
"version": "0.28.0",
4+
"version": "0.34.1",
55
"description": "Example of Express integration with OpenTelemetry",
6-
"main": "index.js",
76
"scripts": {
87
"zipkin:server": "cross-env EXPORTER=zipkin ts-node src/server.ts",
98
"zipkin:client": "cross-env EXPORTER=zipkin ts-node src/client.ts",
109
"jaeger:server": "cross-env EXPORTER=jaeger ts-node src/server.ts",
1110
"jaeger:client": "cross-env EXPORTER=jaeger ts-node src/client.ts",
12-
"compile": "tsc -p ."
11+
"compile": "tsc -p .",
12+
"setup": "cd ../../../../ && npm ci && cd plugins/node/opentelemetry-instrumentation-express && npm run compile && cd examples && npm run compile"
1313
},
1414
"repository": {
1515
"type": "git",
16-
"url": "git+ssh://[email protected]/open-telemetry/opentelemetry-js.git"
16+
"url": "git+ssh://[email protected]/open-telemetry/opentelemetry-js-contrib.git",
17+
"directory": "plugins/node/opentelemetry-instrumentation-express"
1718
},
1819
"keywords": [
1920
"opentelemetry",
@@ -26,24 +27,25 @@
2627
"author": "OpenTelemetry Authors",
2728
"license": "Apache-2.0",
2829
"bugs": {
29-
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
30+
"url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues"
3031
},
32+
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express/examples#readme",
3133
"dependencies": {
32-
"@opentelemetry/api": "^1.0.0",
33-
"@opentelemetry/exporter-jaeger": "^1.0.0",
34-
"@opentelemetry/exporter-zipkin": "^1.0.0",
34+
"@opentelemetry/api": "^1.3.0",
35+
"@opentelemetry/exporter-jaeger": "^1.18.1",
36+
"@opentelemetry/exporter-trace-otlp-proto": "^0.46.0",
37+
"@opentelemetry/exporter-zipkin": "^1.18.1",
3538
"@opentelemetry/instrumentation": "^0.46.0",
36-
"@opentelemetry/instrumentation-express": "0.28.0",
39+
"@opentelemetry/instrumentation-express": "^0.34.1",
3740
"@opentelemetry/instrumentation-http": "^0.46.0",
38-
"@opentelemetry/resources": "^1.0.0",
39-
"@opentelemetry/sdk-trace-base": "^1.0.0",
40-
"@opentelemetry/sdk-trace-node": "^1.0.0",
41-
"@opentelemetry/semantic-conventions": "^1.0.0",
41+
"@opentelemetry/resources": "^1.18.1",
42+
"@opentelemetry/sdk-trace-base": "^1.18.1",
43+
"@opentelemetry/sdk-trace-node": "^1.18.1",
44+
"@opentelemetry/semantic-conventions": "^1.18.1",
4245
"axios": "^1.6.0",
4346
"cross-env": "^7.0.3",
4447
"express": "^4.17.1"
4548
},
46-
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme",
4749
"devDependencies": {
4850
"@types/express": "^4.17.13",
4951
"ts-node": "^10.6.0",

plugins/node/opentelemetry-instrumentation-express/examples/src/tracer.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
'use strict';
22

3-
import { Sampler, SpanKind } from "@opentelemetry/api";
3+
import { SpanKind, Attributes } from "@opentelemetry/api";
44

55
const opentelemetry = require('@opentelemetry/api');
66

77
// Not functionally required but gives some insight what happens behind the scenes
88
const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry;
99
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
1010

11-
import { AlwaysOnSampler } from '@opentelemetry/core';
1211
import { registerInstrumentations } from '@opentelemetry/instrumentation';
1312
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
14-
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
15-
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
13+
import { Sampler, AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
14+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
1615
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
1716
import { Resource } from '@opentelemetry/resources';
1817
import { SemanticAttributes, SemanticResourceAttributes as ResourceAttributesSC } from '@opentelemetry/semantic-conventions';
19-
import { SpanAttributes } from "@opentelemetry/api/build/src/trace/attributes";
2018

21-
const Exporter = (process.env.EXPORTER || '').toLowerCase().startsWith('z') ? ZipkinExporter : JaegerExporter;
19+
const Exporter = (process.env.EXPORTER || '').toLowerCase().startsWith('z') ? ZipkinExporter : OTLPTraceExporter;
2220
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
2321
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
2422

@@ -50,7 +48,7 @@ export const setupTracing = (serviceName: string) => {
5048
return opentelemetry.trace.getTracer(serviceName);
5149
};
5250

53-
type FilterFunction = (spanName: string, spanKind: SpanKind, attributes: SpanAttributes) => boolean;
51+
type FilterFunction = (spanName: string, spanKind: SpanKind, attributes: Attributes) => boolean;
5452

5553
function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
5654
return {
@@ -66,6 +64,6 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
6664
}
6765
}
6866

69-
function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: SpanAttributes) {
67+
function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: Attributes) {
7068
return spanKind !== opentelemetry.SpanKind.SERVER || attributes[SemanticAttributes.HTTP_ROUTE] !== "/health";
7169
}

0 commit comments

Comments
 (0)