Skip to content

Commit

Permalink
chore(mongodb): migrate mongodb examples (open-telemetry#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
osherv authored Sep 19, 2022
1 parent ea9eea3 commit e0a2e8e
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 146 deletions.
1 change: 0 additions & 1 deletion examples/fastify/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ async function subsystem(fastify) {
done();
}, 2000);
});

}

app.post('/run_test/:id', async (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-http');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');

const provider = new NodeTracerProvider({
resource: new Resource({
Expand Down
6 changes: 4 additions & 2 deletions examples/grpc-census-prop/capitalize_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ const { Fetch } = grpc.load(PROTO_PATH).rpc;
* Creates a gRPC client, makes a gRPC call and waits before shutting down
*/
function main() {
const client = new Fetch('localhost:50051',
grpc.credentials.createInsecure());
const client = new Fetch(
'localhost:50051',
grpc.credentials.createInsecure(),
);
const data = process.argv[2] || 'opentelemetry';
console.log('> ', data);

Expand Down
6 changes: 4 additions & 2 deletions examples/grpc_dynamic_codegen/capitalize_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS);
const rpcProto = grpc.loadPackageDefinition(definition).rpc;

function main() {
const client = new rpcProto.Fetch('localhost:50051',
grpc.credentials.createInsecure());
const client = new rpcProto.Fetch(
'localhost:50051',
grpc.credentials.createInsecure(),
);
const data = process.argv[2] || 'opentelemetry';
console.log('> ', data);

Expand Down
45 changes: 0 additions & 45 deletions examples/mongodb/package.json

This file was deleted.

36 changes: 0 additions & 36 deletions examples/mongodb/tracer.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
examples
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/

### Zipkin

- Start MongoDB server via docker

```sh
# from this directory
npm run docker:start
```

- Run the server

```sh
# from this directory
npm run server
npm run zipkin:server
```

- Run the client
- Run the zipkin:client

```sh
# from this directory
Expand All @@ -42,22 +49,29 @@ Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/
`server` script should output the `traceid` in the terminal (e.g `traceid: 4815c3d576d930189725f1f1d1bdfcc6`).
Go to Zipkin with your browser <http://localhost:9411/zipkin/traces/(your-trace-id)> (e.g <http://localhost:9411/zipkin/traces/4815c3d576d930189725f1f1d1bdfcc6>)

<p align="center"><img src="./images/zipkin-ui.png?raw=true"/></p>
<p align="center"><img src="./images/zipkin.png?raw=true"/></p>

### Jaeger

- Start MongoDB server via docker

```sh
# from this directory
npm run docker:start
```

- Run the server

```sh
# from this directory
npm run server
npm run jaeger:server
```

- Run the client

```sh
# from this directory
npm run client
npm run jaeger:client
```

#### Jaeger UI
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "mongodb-example",
"private": true,
"version": "0.28.0",
"description": "Example of mongodb integration with OpenTelemetry",
"main": "index.js",
"scripts": {
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
"zipkin:server": "cross-env EXPORTER=zipkin ts-node src/server.ts",
"zipkin:client": "cross-env EXPORTER=zipkin ts-node src/client.ts",
"jaeger:server": "cross-env EXPORTER=jaeger ts-node src/server.ts",
"jaeger:client": "cross-env EXPORTER=jaeger ts-node src/client.ts",
"compile": "tsc -p ."
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/open-telemetry/opentelemetry-js-contrib.git"
},
"keywords": [
"opentelemetry",
"mongodb",
"tracing"
],
"engines": {
"node": ">=8.12.0"
},
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues"
},
"dependencies": {
"@opentelemetry/api": "^1.0.0",
"@opentelemetry/exporter-jaeger": "^1.0.0",
"@opentelemetry/exporter-zipkin": "^1.0.0",
"@opentelemetry/instrumentation": "^0.32.0",
"@opentelemetry/instrumentation-http": "^0.32.0",
"@opentelemetry/instrumentation-mongodb": "^0.32.0",
"@opentelemetry/sdk-trace-node": "^1.0.0",
"@opentelemetry/sdk-trace-base": "^1.0.0",
"mongodb": "^3.5.7"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme",
"devDependencies": {
"cross-env": "^7.0.3",
"ts-node": "^10.6.0",
"typescript": "4.3.5"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

const api = require('@opentelemetry/api');
const tracer = require('./tracer')('example-mongodb-http-client');
// eslint-disable-next-line import/order
const http = require('http');
import * as api from '@opentelemetry/api';
import { setupTracing } from './tracer';

const tracer = setupTracing('example-mongodb-http-client')
import * as http from 'http';


/** A function which makes requests and handles response. */
function makeRequest() {
Expand All @@ -22,7 +24,7 @@ function makeRequest() {
port: 8080,
path: '/collection/',
}, (response) => {
const body = [];
const body: any = [];
response.on('data', (chunk) => body.push(chunk));
response.on('end', () => {
responses += 1;
Expand All @@ -38,7 +40,7 @@ function makeRequest() {
port: 8080,
path: '/insert/',
}, (response) => {
const body = [];
const body: any = [];
response.on('data', (chunk) => body.push(chunk));
response.on('end', () => {
responses += 1;
Expand All @@ -54,7 +56,7 @@ function makeRequest() {
port: 8080,
path: '/get/',
}, (response) => {
const body = [];
const body: any = [];
response.on('data', (chunk) => body.push(chunk));
response.on('end', () => {
responses += 1;
Expand Down
Loading

0 comments on commit e0a2e8e

Please sign in to comment.