forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: memcached instrumentation (open-telemetry#539)
- Loading branch information
Showing
19 changed files
with
1,131 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Overview | ||
|
||
OpenTelemetry Memcached instrumentation allows user to automatically collect trace data from queries made by the client and export them to the backend of choice. This example does not showcase export functionality, but there are numerous other examples doing that: [`express`](../express), [`router`](../router). | ||
|
||
## Running the Example | ||
|
||
Created spans are printed out to stdout while running the example. | ||
|
||
```sh | ||
npm install # install the dependencies | ||
npm run docker:start # start memcached server | ||
npm run start # run the example | ||
npm run docker:stop # spin down and clean up the docker container | ||
``` | ||
|
||
## LICENSE | ||
|
||
Apache License 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
require('./tracer')('example-resource'); | ||
const Memcached = require('memcached'); | ||
const assert = require('assert'); | ||
|
||
const KEY = '_KEY_'; | ||
const VALUE = `RAND:${Math.random().toFixed(4)}`; | ||
const LT = 10; | ||
const client = new Memcached(); | ||
|
||
client.set(KEY, VALUE, LT, (err) => { | ||
assert.strictEqual(err, undefined); | ||
client.get(KEY, (err, result) => { | ||
assert.strictEqual(err, undefined); | ||
assert.strictEqual(result, VALUE); | ||
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); | ||
setTimeout(() => { console.log('Completed.'); }, 5000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "memcached-example", | ||
"private": true, | ||
"version": "0.22.0", | ||
"description": "Example of Memcached client with OpenTelemetry", | ||
"main": "index.js", | ||
"scripts": { | ||
"docker:start": "docker run --rm -d --name otel-memcached -p 11211:11211 memcached:1.6.9-alpine", | ||
"docker:stop": "docker rm -f otel-memcached", | ||
"start": "node index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/open-telemetry/opentelemetry-js-contrib.git" | ||
}, | ||
"keywords": [ | ||
"opentelemetry", | ||
"instrumentation", | ||
"memcached", | ||
"tracing" | ||
], | ||
"engines": { | ||
"node": ">=8.5.0" | ||
}, | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.0.1", | ||
"@opentelemetry/instrumentation": "^0.22.0", | ||
"@opentelemetry/instrumentation-memcached": "^0.22.0", | ||
"@opentelemetry/node": "^0.22.0", | ||
"@opentelemetry/tracing": "^0.22.0", | ||
"memcached": "^2.2.2" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const opentelemetry = require('@opentelemetry/api'); | ||
|
||
const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry; | ||
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.VERBOSE); | ||
|
||
const { registerInstrumentations } = require('@opentelemetry/instrumentation'); | ||
const { NodeTracerProvider } = require('@opentelemetry/node'); | ||
const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/tracing'); | ||
const { Resource } = require('@opentelemetry/resources'); | ||
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); | ||
|
||
const { MemcachedInstrumentation } = require('@opentelemetry/instrumentation-memcached'); | ||
|
||
module.exports = (serviceName) => { | ||
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[ResourceAttributes.SERVICE_NAME]: serviceName, | ||
}), | ||
}); | ||
registerInstrumentations({ | ||
tracerProvider: provider, | ||
instrumentations: [ | ||
new MemcachedInstrumentation(), | ||
], | ||
}); | ||
|
||
const exporter = new ConsoleSpanExporter(); | ||
|
||
provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); | ||
|
||
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings | ||
provider.register(); | ||
|
||
return opentelemetry.trace.getTracer('memcached-example'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
plugins/node/opentelemetry-instrumentation-memcached/.eslintignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
7 changes: 7 additions & 0 deletions
7
plugins/node/opentelemetry-instrumentation-memcached/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
"env": { | ||
"mocha": true, | ||
"node": true | ||
}, | ||
...require('../../../eslint.config.js') | ||
} |
4 changes: 4 additions & 0 deletions
4
plugins/node/opentelemetry-instrumentation-memcached/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/bin | ||
/coverage | ||
/doc | ||
/test |
Oops, something went wrong.