Skip to content

Commit

Permalink
docs: add ioredis example (#665)
Browse files Browse the repository at this point in the history
* docs: add ioredis example

* refactor: simplify example

* fix: ioredis example

* fix: tracerRegistry not tracer

* fix: test only with set command

* fix: only use Jaeger as backend

Signed-off-by: Naseem <[email protected]>

Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
Naseem and dyladan committed Jan 28, 2020
1 parent 8711f2b commit 3dd2a68
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/ioredis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Overview

OpenTelemetry IORedis Instrumentation allows the user to automatically collect trace data and export them to the backend(s) of choice (Jaeger in this example).

## Tracing backend setup

### Jaeger

- Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/#all-in-one)

## Installation

```sh
npm install
```

## Run the Application

- Start redis via docker

```sh
npm run docker:start
```

- Run the main program

```sh
npm run start
```

- Cleanup docker

```sh
npm run docker:stop
```

## LICENSE

Apache License 2.0
19 changes: 19 additions & 0 deletions examples/ioredis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

// Require tracer before any other modules
require('./tracer');
const Redis = require('ioredis');

const redis = new Redis();

async function main() {
try {
await redis.set('test', 'data');
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
}

main();
40 changes: 40 additions & 0 deletions examples/ioredis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "ioredis-example",
"private": true,
"version": "0.3.3",
"description": "Example of HTTP integration with OpenTelemetry",
"main": "index.js",
"scripts": {
"docker:start": "docker run -d -p 6379:6379 --name otjsredis redis:alpine",
"docker:stop": "docker stop otjsredis && docker rm otjsredis",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/open-telemetry/opentelemetry-js.git"
},
"keywords": [
"opentelemetry",
"redis",
"ioredis",
"tracing"
],
"engines": {
"node": ">=8"
},
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
"@opentelemetry/plugin-ioredis": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"ioredis": "^4.14.1"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme",
"devDependencies": {}
}
17 changes: 17 additions & 0 deletions examples/ioredis/tracer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');

const tracerRegistry = new NodeTracerRegistry();

const exporter = new JaegerExporter({ serviceName: 'ioredis-example' });

tracerRegistry.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracerRegistry(tracerRegistry);

module.exports = opentelemetry.getTracer();

0 comments on commit 3dd2a68

Please sign in to comment.