Skip to content

Commit 336b7b5

Browse files
authored
Merge branch 'main' into dsvanlani/update-mongodb-kebab-2528
2 parents 6df908e + 2f5d1de commit 336b7b5

File tree

15 files changed

+67
-82
lines changed

15 files changed

+67
-82
lines changed

examples/express/README.md

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Overview
22

3-
OpenTelemetry Express Instrumentation allows the user to automatically collect trace data and export them to the backend of choice (we can use Zipkin or Jaeger for this example), to give observability to distributed systems.
3+
OpenTelemetry Express Instrumentation allows the user to automatically collect trace data and export them to the backend of choice (we use Jaeger for this example), to give observability to distributed systems.
44

55
This is a simple example that demonstrates tracing calls made to Express API. The example
66
shows key aspects of tracing such as
@@ -17,44 +17,34 @@ shows key aspects of tracing such as
1717
npm install
1818
```
1919

20-
Setup [Zipkin Tracing](https://zipkin.io/pages/quickstart.html)
21-
or
22-
Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/#all-in-one)
23-
24-
## Run the Application
25-
26-
### Zipkin
27-
28-
Run the server:
29-
30-
```sh
31-
npm run zipkin:server
20+
Start Jaeger in Docker for receiving tracing data (see [the Jaeger docs](https://www.jaegertracing.io/docs/2.0/getting-started/#in-docker) for more details about running Jaeger):
21+
22+
```bash
23+
docker run --rm --name jaeger \
24+
-p 5778:5778 \
25+
-p 16686:16686 \
26+
-p 4317:4317 \
27+
-p 4318:4318 \
28+
-p 14250:14250 \
29+
-p 14268:14268 \
30+
-p 9411:9411 \
31+
jaegertracing/jaeger:2.0.0 \
32+
--set receivers.otlp.protocols.http.endpoint=0.0.0.0:4318 \
33+
--set receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317
3234
```
3335

34-
Then run the client in a separate terminal:
35-
36-
```sh
37-
npm run zipkin:client
38-
```
39-
40-
After a short time, the generated traces should be available in the Zipkin UI.
41-
Visit <http://localhost:9411/zipkin> and click the "RUN QUERY" button to view
42-
recent traces, then click "SHOW" on a given trace.
43-
44-
<p align="center"><img alt="Zipkin UI with trace" src="./images/zipkin.jpg?raw=true"/></p>
45-
46-
### Jaeger
36+
## Run the Application
4737

4838
Run the server:
4939

5040
```sh
51-
npm run jaeger:server
41+
npm run server
5242
```
5343

5444
Then run the client in a separate terminal:
5545

5646
```sh
57-
npm run jaeger:client
47+
npm run client
5848
```
5949

6050
Visit the Jaeger UI at <http://localhost:16686/search>, select a service (e.g. "example-express-client"), click "Find Traces", then click on a trace to view it.

examples/express/images/zipkin.jpg

-102 KB
Binary file not shown.

examples/express/package.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
"version": "0.1.0",
55
"description": "Example of Express integration with OpenTelemetry",
66
"scripts": {
7-
"zipkin:server": "cross-env EXPORTER=zipkin ts-node src/server.ts",
8-
"zipkin:client": "cross-env EXPORTER=zipkin ts-node src/client.ts",
9-
"jaeger:server": "cross-env EXPORTER=jaeger ts-node src/server.ts",
10-
"jaeger:client": "cross-env EXPORTER=jaeger ts-node src/client.ts",
7+
"server": "ts-node src/server.ts",
8+
"client": "ts-node src/client.ts",
119
"compile": "tsc -p ."
1210
},
1311
"repository": {
@@ -30,23 +28,21 @@
3028
},
3129
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/express#readme",
3230
"dependencies": {
33-
"@opentelemetry/api": "^1.3.0",
34-
"@opentelemetry/exporter-jaeger": "^1.18.1",
35-
"@opentelemetry/exporter-trace-otlp-proto": "^0.48.0",
36-
"@opentelemetry/exporter-zipkin": "^1.18.1",
37-
"@opentelemetry/instrumentation": "^0.48.0",
38-
"@opentelemetry/instrumentation-express": "^0.34.1",
39-
"@opentelemetry/instrumentation-http": "^0.48.0",
40-
"@opentelemetry/resources": "^1.18.1",
41-
"@opentelemetry/sdk-trace-base": "^1.18.1",
42-
"@opentelemetry/sdk-trace-node": "^1.18.1",
31+
"@opentelemetry/api": "^1.9.0",
32+
"@opentelemetry/exporter-trace-otlp-proto": "^0.54.2",
33+
"@opentelemetry/instrumentation": "^0.54.2",
34+
"@opentelemetry/instrumentation-express": "^0.44.0",
35+
"@opentelemetry/instrumentation-http": "^0.54.2",
36+
"@opentelemetry/resources": "^1.27.0",
37+
"@opentelemetry/sdk-trace-base": "^1.27.0",
38+
"@opentelemetry/sdk-trace-node": "^1.27.0",
4339
"@opentelemetry/semantic-conventions": "^1.27.0",
4440
"axios": "^1.6.0",
45-
"cross-env": "^7.0.3",
4641
"express": "^4.17.1"
4742
},
4843
"devDependencies": {
4944
"@types/express": "^4.17.13",
45+
"@types/node": "18.18.14",
5046
"ts-node": "^10.6.0",
5147
"typescript": "4.4.4"
5248
}

examples/express/src/tracer.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,39 @@
11
'use strict';
22

3-
import { SpanKind, Attributes } from "@opentelemetry/api";
4-
5-
const opentelemetry = require('@opentelemetry/api');
6-
7-
// Not functionally required but gives some insight what happens behind the scenes
8-
const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry;
9-
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
10-
3+
import { trace, SamplingDecision, SpanKind, Attributes } from '@opentelemetry/api';
114
import { registerInstrumentations } from '@opentelemetry/instrumentation';
125
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
136
import { Sampler, AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
147
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
15-
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
168
import { Resource } from '@opentelemetry/resources';
17-
import { SEMRESATTRS_SERVICE_NAME, SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
18-
19-
const Exporter = (process.env.EXPORTER || '').toLowerCase().startsWith('z') ? ZipkinExporter : OTLPTraceExporter;
9+
import { ATTR_SERVICE_NAME, ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2010
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
21-
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
11+
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
2212

2313
export const setupTracing = (serviceName: string) => {
2414
const provider = new NodeTracerProvider({
2515
resource: new Resource({
26-
[SEMRESATTRS_SERVICE_NAME]: serviceName,
16+
[ATTR_SERVICE_NAME]: serviceName,
2717
}),
2818
sampler: filterSampler(ignoreHealthCheck, new AlwaysOnSampler()),
2919
});
3020
registerInstrumentations({
3121
tracerProvider: provider,
3222
instrumentations: [
3323
// Express instrumentation expects HTTP layer to be instrumented
34-
HttpInstrumentation,
35-
ExpressInstrumentation,
24+
new HttpInstrumentation(),
25+
new ExpressInstrumentation(),
3626
],
3727
});
3828

39-
const exporter = new Exporter({
40-
serviceName,
41-
});
29+
const exporter = new OTLPTraceExporter({});
4230

4331
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
4432

4533
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
4634
provider.register();
4735

48-
return opentelemetry.trace.getTracer(serviceName);
36+
return trace.getTracer(serviceName);
4937
};
5038

5139
type FilterFunction = (spanName: string, spanKind: SpanKind, attributes: Attributes) => boolean;
@@ -54,7 +42,7 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
5442
return {
5543
shouldSample(ctx, tid, spanName, spanKind, attr, links) {
5644
if (!filterFn(spanName, spanKind, attr)) {
57-
return { decision: opentelemetry.SamplingDecision.NOT_RECORD };
45+
return { decision: SamplingDecision.NOT_RECORD };
5846
}
5947
return parent.shouldSample(ctx, tid, spanName, spanKind, attr, links);
6048
},
@@ -65,5 +53,5 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
6553
}
6654

6755
function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: Attributes) {
68-
return spanKind !== opentelemetry.SpanKind.SERVER || attributes[SEMATTRS_HTTP_ROUTE] !== "/health";
56+
return spanKind !== SpanKind.SERVER || attributes[ATTR_HTTP_ROUTE] !== "/health";
6957
}

examples/web/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/web/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ This example shows how to use [@opentelemetry/sdk-trace-web][] with different in
99
npm install
1010
```
1111

12+
## Start a collector and trace viewer
13+
14+
Optionally, you can use the provided Docker Compose file to start an OpenTelemetry Collector and a Zipkin to view collected traces.
15+
You can skip this step if you have your own collector already setup.
16+
17+
```sh
18+
npm run docker:start
19+
```
20+
1221
## Run the Application
1322

1423
```sh
1524
# from this directory
1625
npm start
1726
```
1827

19-
By default, the application will run on port `8090`.
28+
- Open the application at <http://localhost:8090>.
29+
- Click around in each of the example sub-paths to create some tracing data.
30+
- Open Zipkin at <http://127.0.0.1:9411/zipkin/> and search for some traces (click "Run Query").
31+
2032

2133
## More information
2234

examples/web/docker/collector-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ receivers:
33
protocols:
44
grpc:
55
http:
6-
cors_allowed_origins:
7-
- http://*
8-
- https://*
6+
cors:
7+
allowed_origins:
8+
- http://*
9+
- https://*
910

1011
exporters:
1112
zipkin:

examples/web/docker/docker-compose.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
version: "3"
21
services:
3-
# Collector
42
collector:
5-
image: otel/opentelemetry-collector:0.38.0
3+
image: otel/opentelemetry-collector:0.99.0
64
command: ["--config=/conf/collector-config.yaml"]
75
volumes:
86
- ./collector-config.yaml:/conf/collector-config.yaml
@@ -13,7 +11,6 @@ services:
1311
depends_on:
1412
- zipkin-all-in-one
1513

16-
# Zipkin
1714
zipkin-all-in-one:
1815
image: openzipkin/zipkin:latest
1916
ports:

examples/web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"description": "Example of using web plugins in browser",
66
"main": "index.js",
77
"scripts": {
8-
"docker:start": "cd ./docker && docker-compose down && docker-compose up",
9-
"docker:startd": "cd ./docker && docker-compose down && docker-compose up -d",
8+
"docker:start": "cd ./docker && docker compose down && docker compose up",
9+
"docker:startd": "cd ./docker && docker compose down && docker compose up -d",
1010
"start": "webpack-dev-server --progress --color --port 8090 --config ./webpack.config.js --hot --host 0.0.0.0"
1111
},
1212
"repository": {

plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,5 @@ function wrapPromise<T>(
392392
}
393393

394394
function truncateQuery(query: unknown, maxQueryLength: number) {
395-
return String(query).substr(0, maxQueryLength);
395+
return String(query).substring(0, maxQueryLength);
396396
}

0 commit comments

Comments
 (0)