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

Named Tracers / Tracer Registry #582

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d75f53e
feat: spike of named tracer registry
dyladan Dec 2, 2019
ead9f16
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 2, 2019
50927cd
chore: mysql/mongo tracer registry support
dyladan Dec 2, 2019
c686117
fix: lint
dyladan Dec 2, 2019
7dba62c
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 2, 2019
14fa061
chore: add getTracer back
dyladan Dec 2, 2019
b1e887c
chore: change default tracer name to empty string
dyladan Dec 2, 2019
5ca0209
fix: lint
dyladan Dec 2, 2019
217d3b3
Merge branch 'master' into tracer-registry
dyladan Dec 2, 2019
61f4618
chore: update examples for registry
dyladan Dec 2, 2019
33dd773
Merge branch 'tracer-registry' of github.com:dynatrace-oss-contrib/op…
dyladan Dec 2, 2019
6f81608
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 10, 2019
0687f1c
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 17, 2019
cc4eba9
chore(tracer-registry): make name required
dyladan Dec 17, 2019
9d95597
chore: lint
dyladan Dec 17, 2019
3237f99
chore: update examples for required tracer name
dyladan Dec 17, 2019
643e286
chore: remove unused tracer delegate
dyladan Dec 17, 2019
508ff33
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 18, 2019
41c1168
chore: remove references to basic tracer
dyladan Dec 23, 2019
6a94efe
chore: remove references to NodeTracer
dyladan Dec 23, 2019
4693d22
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 26, 2019
13f96fd
chore: update xhr for tracer registry
dyladan Dec 26, 2019
38ffef8
chore: update tracer names to match package names
dyladan Dec 26, 2019
9915a2c
chore: add version script to all packages
dyladan Dec 26, 2019
69ff01f
chore: update plugins to use version script
dyladan Dec 26, 2019
40c4301
chore: add jsdoc to noop tracer registry
dyladan Dec 27, 2019
1eea9d2
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 27, 2019
660f41f
chore: update ioredis for tracer registry
dyladan Dec 27, 2019
8e6399e
chore: update pg pool for tracer registry
dyladan Dec 27, 2019
bd0be2c
fix: lint
dyladan Dec 30, 2019
30a1b36
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Jan 3, 2020
7c39151
chore: fix tests
dyladan Jan 3, 2020
e814df6
chore: lint
dyladan Jan 3, 2020
0ec5b82
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Jan 6, 2020
cd47354
chore: lint
dyladan Jan 6, 2020
bfa8bfa
Merge branch 'master' into tracer-registry
mayurkale22 Jan 9, 2020
5740098
Merge branch 'master' into tracer-registry
mayurkale22 Jan 9, 2020
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
Prev Previous commit
Next Next commit
chore: update ioredis for tracer registry
  • Loading branch information
dyladan committed Dec 27, 2019
commit 660f41f9f56dae1e688501f391a047954f824517
3 changes: 2 additions & 1 deletion packages/opentelemetry-plugin-ioredis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"clean": "rimraf build/*",
"check": "gts check",
"precompile": "tsc --version",
"compile": "tsc -p .",
"version:update": "node scripts/version-update.js",
"compile": "npm run version:update && tsc -p .",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"fix": "gts fix",
"prepare": "npm run compile"
Expand Down
47 changes: 47 additions & 0 deletions packages/opentelemetry-plugin-ioredis/scripts/version-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const license =
`/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
`;

const fs = require('fs');
const path = require('path');

const appRoot = path.resolve(__dirname);
const fileUrl = path.resolve(`${appRoot}/../src/version.ts`);
const packageJsonUrl = path.resolve(`${appRoot}/../package.json`);
const pjson = require(packageJsonUrl);
const content = `
// this is autogenerated file, see scripts/version-update.js
export const VERSION = '${pjson.version}';
`;

fs.writeFileSync(fileUrl, `${license}${content}`);
3 changes: 2 additions & 1 deletion packages/opentelemetry-plugin-ioredis/src/ioredis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import { BasePlugin } from '@opentelemetry/core';
import * as ioredisTypes from 'ioredis';
import * as shimmer from 'shimmer';
import { traceConnection, traceSendCommand } from './utils';
import { VERSION } from './version';

export class IORedisPlugin extends BasePlugin<typeof ioredisTypes> {
static readonly COMPONENT = 'ioredis';
static readonly DB_TYPE = 'redis';
readonly supportedVersions = ['^2.0.0'];

constructor(readonly moduleName: string) {
super();
super('@opentelemetry/plugin-ioredis', VERSION);
}

protected patch(): typeof ioredisTypes {
Expand Down
18 changes: 18 additions & 0 deletions packages/opentelemetry-plugin-ioredis/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// this is autogenerated file, see scripts/version-update.js
export const VERSION = '0.3.1';
58 changes: 29 additions & 29 deletions packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/tracing';
import { NodeTracer } from '@opentelemetry/node';
import { NodeTracerRegistry } from '@opentelemetry/node';
import { plugin, IORedisPlugin } from '../src';
import * as ioredisTypes from 'ioredis';
import { NoopLogger } from '@opentelemetry/core';
Expand Down Expand Up @@ -49,7 +49,7 @@ const okStatus: Status = {
};

describe('ioredis', () => {
const tracer = new NodeTracer();
const registry = new NodeTracerRegistry();
let ioredis: typeof ioredisTypes;
const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL;
const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal;
Expand All @@ -68,8 +68,8 @@ describe('ioredis', () => {
}

ioredis = require('ioredis');
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
plugin.enable(ioredis, tracer, new NoopLogger());
registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
plugin.enable(ioredis, registry, new NoopLogger());
});

after(() => {
Expand All @@ -84,7 +84,7 @@ describe('ioredis', () => {

describe('#createClient()', () => {
it('should propagate the current span to event handlers', done => {
const span = tracer.startSpan('test span');
const span = registry.getTracer("ioredis-test").startSpan('test span');
let client: ioredisTypes.Redis;
const attributes = {
...DEFAULT_ATTRIBUTES,
Expand All @@ -93,7 +93,7 @@ describe('ioredis', () => {
const readyHandler = () => {
const endedSpans = memoryExporter.getFinishedSpans();

assert.strictEqual(tracer.getCurrentSpan(), span);
assert.strictEqual(registry.getTracer("ioredis-test").getCurrentSpan(), span);
assert.strictEqual(endedSpans.length, 2);
assert.strictEqual(endedSpans[0].name, `connect`);
assert.strictEqual(endedSpans[1].name, `info`);
Expand All @@ -119,7 +119,7 @@ describe('ioredis', () => {
client.quit(done);
};

tracer.withSpan(span, () => {
registry.getTracer("ioredis-test").withSpan(span, () => {
client = new ioredis(URL);
client.on('ready', readyHandler);
client.on('error', errorHandler);
Expand Down Expand Up @@ -183,8 +183,8 @@ describe('ioredis', () => {
' '
)}`,
};
const span = tracer.startSpan('test span');
tracer.withSpan(span, () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
registry.getTracer("ioredis-test").withSpan(span, () => {
command.method((err, _result) => {
assert.ifError(err);
assert.strictEqual(memoryExporter.getFinishedSpans().length, 1);
Expand All @@ -211,8 +211,8 @@ describe('ioredis', () => {
...DEFAULT_ATTRIBUTES,
[AttributeNames.DB_STATEMENT]: 'hset hash random random',
};
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
await registry.getTracer("ioredis-test").withSpan(span, async () => {
try {
await client.hset('hash', 'random', 'random');
assert.strictEqual(memoryExporter.getFinishedSpans().length, 1);
Expand All @@ -239,8 +239,8 @@ describe('ioredis', () => {
...DEFAULT_ATTRIBUTES,
[AttributeNames.DB_STATEMENT]: 'scan 0',
};
const span = tracer.startSpan('test span');
tracer.withSpan(span, () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
registry.getTracer("ioredis-test").withSpan(span, () => {
const stream = client.scanStream();
stream
.on('data', resultKeys => {
Expand Down Expand Up @@ -275,8 +275,8 @@ describe('ioredis', () => {
});

it('should create a child span for pubsub', async () => {
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
await registry.getTracer("ioredis-test").withSpan(span, async () => {
try {
const pub = new ioredis(URL);
const sub = new ioredis(URL);
Expand Down Expand Up @@ -334,8 +334,8 @@ describe('ioredis', () => {
[AttributeNames.DB_STATEMENT]: 'eval return {KEYS[1],ARGV[1]} 1 test',
};

const span = tracer.startSpan('test span');
tracer.withSpan(span, () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
registry.getTracer("ioredis-test").withSpan(span, () => {
// This will define a command echo:
client.defineCommand('echo', {
numberOfKeys: 1,
Expand Down Expand Up @@ -372,8 +372,8 @@ describe('ioredis', () => {
[AttributeNames.DB_STATEMENT]: 'multi',
};

const span = tracer.startSpan('test span');
tracer.withSpan(span, () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
registry.getTracer("ioredis-test").withSpan(span, () => {
client
.multi()
.set('foo', 'bar')
Expand Down Expand Up @@ -408,8 +408,8 @@ describe('ioredis', () => {
[AttributeNames.DB_STATEMENT]: 'set foo bar',
};

const span = tracer.startSpan('test span');
tracer.withSpan(span, () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
registry.getTracer("ioredis-test").withSpan(span, () => {
const pipeline = client.pipeline();
pipeline.set('foo', 'bar');
pipeline.del('cc');
Expand Down Expand Up @@ -441,8 +441,8 @@ describe('ioredis', () => {
...DEFAULT_ATTRIBUTES,
[AttributeNames.DB_STATEMENT]: 'get test',
};
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
await registry.getTracer("ioredis-test").withSpan(span, async () => {
try {
const value = await client.get('test');
assert.strictEqual(value, 'data');
Expand Down Expand Up @@ -470,8 +470,8 @@ describe('ioredis', () => {
...DEFAULT_ATTRIBUTES,
[AttributeNames.DB_STATEMENT]: 'del test',
};
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
await registry.getTracer("ioredis-test").withSpan(span, async () => {
try {
const result = await client.del('test');
assert.strictEqual(result, 1);
Expand Down Expand Up @@ -502,8 +502,8 @@ describe('ioredis', () => {

IOREDIS_CALLBACK_OPERATIONS.forEach(operation => {
it(`should not create a child span for cb style ${operation.description}`, done => {
const span = tracer.startSpan('test span');
tracer.withSpan(span, () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
registry.getTracer("ioredis-test").withSpan(span, () => {
operation.method((err, _) => {
assert.ifError(err);
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);
Expand All @@ -518,8 +518,8 @@ describe('ioredis', () => {
});

it('should not create a child span for hset promise upon error', async () => {
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
const span = registry.getTracer("ioredis-test").startSpan('test span');
await registry.getTracer("ioredis-test").withSpan(span, async () => {
try {
await client.hset('hash', 'random', 'random');
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);
Expand Down