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

docs: add ioredis example #665

Merged
merged 14 commits into from
Jan 28, 2020
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
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyladan should this now be module.exports = opentelemetry.getTracerRegistry(); ?
Should the file be renamed to tracer-registry.js in this case?

As a side note I find this whole tracer registry/factory thing to be confusing for the end user. I wish the focus was that libs just not have broken implementations of tracers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that means it becomes tracer registry.

"just don't have bugs" is not a feasible answer to the problem unfortunately.

Fortunately, most end users won't have to worry about it too much, just library developers. The only change for most end users is the name of the global object they need to create. Most users will never call any methods on the tracer registry manually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining.

Copy link
Member Author

@naseemkullah naseemkullah Jan 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyladan should this now be module.exports = opentelemetry.getTracerRegistry(); ?
Should the file be renamed to tracer-registry.js in this case?

@dyladan I had not yet made the above fix. Do you want a follow up PR for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make a follow up PR to handle it, but you're not actually using the exported value in your index, so it shouldn't matter.