Skip to content

Commit 367b99e

Browse files
committed
@sentry/opentracing (#1918)
* feat: Add opentracing package * feat: Add traceId + references * ref: Rename flush * fix: Also add operation * feat: uuid4 split for spanId * feat: Add link:yarn script * feat: Update package.json * feat: Add event type * ref: Fix span json format * feat: Documenation * fix: Tests
1 parent 13df582 commit 367b99e

27 files changed

+474
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ since we removed some methods from the public API and removed some classes from
4343
- **breaking** [all] build: Use `es6` target instead of esnext for ESM builds
4444
- [all] feat: Prefix all private methods with `_`
4545
- [all] build: Use terser instead of uglify
46+
- [opentracing] feat: Introduce `@sentry/opentracing` providing functions to attach opentracing data to Sentry Events
4647

4748
## 4.6.4
4849

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build:watch": "lerna run build:watch --stream --no-sort --concurrency 9999",
88
"clean": "lerna run --stream clean",
99
"fix": "lerna run --stream --concurrency 1 fix",
10+
"link:yarn": "lerna run --stream --concurrency 1 link:yarn",
1011
"lint": "lerna run --stream --concurrency 1 lint",
1112
"lint:json": "lerna run --stream --concurrency 1 lint:tslint:json",
1213
"test": "lerna run --stream --concurrency 1 --sort test",
@@ -19,6 +20,7 @@
1920
"packages/integrations",
2021
"packages/minimal",
2122
"packages/node",
23+
"packages/opentracing",
2224
"packages/types",
2325
"packages/typescript",
2426
"packages/utils"

packages/browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"build:esm": "tsc -p tsconfig.esm.json",
6060
"build:watch": "rollup --config --watch",
6161
"clean": "rimraf dist coverage .rpt2_cache build esm",
62+
"link:yarn": "yarn link",
6263
"lint": "run-s lint:prettier lint:tslint",
6364
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
6465
"lint:tslint": "tslint -t stylish -p .",

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"build:esm": "tsc -p tsconfig.esm.json",
3838
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3939
"clean": "rimraf dist coverage",
40+
"link:yarn": "yarn link",
4041
"lint": "run-s lint:prettier lint:tslint",
4142
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
4243
"lint:tslint": "tslint -t stylish -p .",

packages/hub/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"build:esm": "tsc -p tsconfig.esm.json",
3636
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3737
"clean": "rimraf dist coverage",
38+
"link:yarn": "yarn link",
3839
"lint": "run-s lint:prettier lint:tslint",
3940
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
4041
"lint:tslint": "tslint -t stylish -p .",

packages/minimal/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"build:esm": "tsc -p tsconfig.esm.json",
3636
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3737
"clean": "rimraf dist coverage",
38+
"link:yarn": "yarn link",
3839
"lint": "run-s lint:prettier lint:tslint",
3940
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
4041
"lint:tslint": "tslint -t stylish -p .",

packages/node/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"build": "tsc -p tsconfig.build.json",
4545
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
4646
"clean": "rimraf dist coverage",
47+
"link:yarn": "yarn link",
4748
"lint": "run-s lint:prettier lint:tslint",
4849
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
4950
"lint:tslint": "tslint -t stylish -p .",

packages/opentracing/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!/dist/**/*
3+
!/esm/**/*

packages/opentracing/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019, Sentry
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/opentracing/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<p align="center">
2+
<a href="https://sentry.io" target="_blank" align="center">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4+
</a>
5+
<br />
6+
</p>
7+
8+
# Sentry JavaScript OpenTracing API
9+
10+
[![npm version](https://img.shields.io/npm/v/@sentry/opentracing.svg)](https://www.npmjs.com/package/@sentry/opentracing)
11+
[![npm dm](https://img.shields.io/npm/dm/@sentry/opentracing.svg)](https://www.npmjs.com/package/@sentry/opentracing)
12+
[![npm dt](https://img.shields.io/npm/dt/@sentry/opentracing.svg)](https://www.npmjs.com/package/@sentry/opentracing)
13+
[![typedoc](https://img.shields.io/badge/docs-typedoc-blue.svg)](http://getsentry.github.io/sentry-javascript/)
14+
15+
## Links
16+
17+
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
18+
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
19+
20+
## General
21+
22+
TBD

packages/opentracing/package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@sentry/opentracing",
3+
"version": "5.0.0-beta0",
4+
"description": "Sentry OpenTracing SDK",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/minimal",
7+
"author": "Sentry",
8+
"license": "BSD-3-Clause",
9+
"engines": {
10+
"node": ">=6"
11+
},
12+
"main": "dist/index.js",
13+
"module": "esm/index.js",
14+
"types": "dist/index.d.ts",
15+
"publishConfig": {
16+
"access": "public"
17+
},
18+
"dependencies": {
19+
"@sentry/hub": "5.0.0-beta0",
20+
"@sentry/utils": "5.0.0-beta0",
21+
"@sentry/types": "5.0.0-beta0",
22+
"opentracing": "0.14.3"
23+
},
24+
"devDependencies": {
25+
"jest": "^24.1.0",
26+
"npm-run-all": "^4.1.2",
27+
"prettier": "^1.16.4",
28+
"prettier-check": "^2.0.0",
29+
"rimraf": "^2.6.3",
30+
"tslint": "^5.12.1",
31+
"typescript": "^3.3.3"
32+
},
33+
"scripts": {
34+
"build": "run-p build:es5 build:esm",
35+
"build:es5": "tsc -p tsconfig.build.json",
36+
"build:esm": "tsc -p tsconfig.esm.json",
37+
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
38+
"clean": "rimraf dist coverage",
39+
"link:yarn": "yarn link",
40+
"lint": "run-s lint:prettier lint:tslint",
41+
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
42+
"lint:tslint": "tslint -t stylish -p .",
43+
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
44+
"fix": "run-s fix:tslint fix:prettier",
45+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
46+
"fix:tslint": "tslint --fix -t stylish -p .",
47+
"test": "jest --passWithNoTests",
48+
"test:watch": "jest --watch --passWithNoTests"
49+
},
50+
"jest": {
51+
"collectCoverage": true,
52+
"transform": {
53+
"^.+\\.ts$": "ts-jest"
54+
},
55+
"moduleFileExtensions": [
56+
"js",
57+
"ts"
58+
],
59+
"testEnvironment": "node",
60+
"testMatch": [
61+
"**/*.test.ts"
62+
],
63+
"globals": {
64+
"ts-jest": {
65+
"tsConfig": "./tsconfig.json",
66+
"diagnostics": false
67+
}
68+
}
69+
},
70+
"sideEffects": false
71+
}

packages/opentracing/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { Span } from './span';
2+
export { Tracer } from './tracer';
3+
export { OpenTracingIntegration as Integration } from './opentracingintegration';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Integration } from '@sentry/types';
2+
import { Tracer } from './tracer';
3+
4+
/**
5+
* Session Tracking Integration
6+
*/
7+
export class OpenTracingIntegration implements Integration {
8+
/**
9+
* @inheritDoc
10+
*/
11+
public name: string = OpenTracingIntegration.id;
12+
13+
/**
14+
* @inheritDoc
15+
*/
16+
public static id: string = 'OpenTracingIntegration';
17+
18+
/**
19+
* Constructor for OpenTracingIntegration
20+
*
21+
* @param traceId Optional TraceId that should be set into the integration.
22+
* @param _tracer Optional custom tracer that should be used.
23+
*/
24+
public constructor(traceId?: string, private readonly _tracer: Tracer = new Tracer()) {
25+
_tracer.setTraceId(traceId);
26+
}
27+
28+
/**
29+
* @inheritDoc
30+
*/
31+
public setupOnce(): void {
32+
const span = this._tracer.startSpan('sdk.init');
33+
span.finish();
34+
setTimeout(() => {
35+
this._tracer.flush();
36+
});
37+
}
38+
39+
/**
40+
* Returns the Tracer which can be used as the parent.
41+
*/
42+
public getTracer(): Tracer {
43+
return this._tracer;
44+
}
45+
}

0 commit comments

Comments
 (0)