Skip to content

feat: APM updates #2161

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

Merged
merged 67 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
214618d
wip: APM
kamilogorek Jul 10, 2019
dd7bb41
Update tracing.ts and hub interface
kamilogorek Jul 10, 2019
48da3f8
feat: Some cleanup and changes
HazAT Jul 11, 2019
fe382e7
feat: Add data/tags to span, Clear finishedSpans
HazAT Jul 12, 2019
8e8de11
fix: Sampled, parent span id and tests
HazAT Jul 16, 2019
b34e42d
fix: Sampled spans
HazAT Jul 16, 2019
4db1f19
fix: Detect internal sentry requests
HazAT Jul 17, 2019
b3f0ed2
meta: Changelog
HazAT Jul 18, 2019
59516ce
ref: Rename SpanProps to SpanContext
HazAT Jul 23, 2019
cff9c0e
fix: SpanContext var name, Timestamp in secs
HazAT Jul 23, 2019
41c974c
feat: Add simple API, timestampWithMs helper
HazAT Jul 23, 2019
494a6f4
fix: Use timestampWithMs
HazAT Jul 23, 2019
790ac56
feat: Expose minimal API
HazAT Jul 24, 2019
4f7b6eb
feat: Add more tests
HazAT Jul 24, 2019
307dd0f
fix: Test
HazAT Jul 24, 2019
4b35daf
meta: beta.3
HazAT Jul 24, 2019
422efcd
meta: beta.4
HazAT Jul 24, 2019
0a83eae
Next iteration of span API
kamilogorek Aug 13, 2019
2e993b3
Add status to transactions
kamilogorek Aug 14, 2019
206c46b
fix: Span changes
HazAT Aug 20, 2019
1b9ebd9
ref: naming
HazAT Aug 21, 2019
1db7ac4
fix: Remove finishSpan from core, node and browser exports
kamilogorek Aug 22, 2019
679d2db
fix: Linter for tests
HazAT Oct 4, 2019
11e3f8b
fix: Add finish method to the Span interface
kamilogorek Oct 9, 2019
3601e3d
Bring APM implementation up to date with python
kamilogorek Oct 23, 2019
8966bf7
feat: Instrument http integration to emit breadcrumbs and/or spans
kamilogorek Oct 25, 2019
a0e1f14
feat: Rework console integration
kamilogorek Oct 28, 2019
53a5d35
feat: tracingHandler for APM
kamilogorek Oct 28, 2019
d5b3df6
feat: Express middleware tracing integration
kamilogorek Oct 28, 2019
74eacc0
fix: Make rewritten http integration work in pre v9 node versions
kamilogorek Oct 28, 2019
e58a8de
ref: Mark failed transactions
kamilogorek Oct 29, 2019
5ca412a
Remove express types from deps and add better docs
kamilogorek Oct 29, 2019
2b21ff7
ref: Pre-release linter and tests patches
kamilogorek Nov 1, 2019
0dfcdc9
meta: Bump to 5.8.0-beta.0
HazAT Nov 1, 2019
4e68f8f
feat: TransactionActivity Integration
HazAT Nov 7, 2019
b6c959e
feat: Finish transaction with timestamp
HazAT Nov 7, 2019
c582e2d
feat: Improvements in transaction creating
HazAT Nov 8, 2019
80a3e02
meta: Bump
HazAT Nov 8, 2019
41b552c
feat: Use timestamp of last span
HazAT Nov 14, 2019
acecb4e
feat: Location change auto transaction
HazAT Nov 15, 2019
5ac8b2b
Merge branch 'master' into apm
HazAT Nov 15, 2019
282d028
fix: Merge
HazAT Nov 15, 2019
fb9a35b
Merge branch 'master' into apm
HazAT Nov 15, 2019
b290681
fix: Comment
HazAT Nov 15, 2019
6697cfa
ref: Uncomment tests for now
HazAT Nov 15, 2019
eb64802
Merge branch 'master' into apm
HazAT Nov 19, 2019
00dcc7d
feat: Add tracingSampleRate
HazAT Nov 19, 2019
9118d31
feat: Auto tracking XHR
HazAT Nov 19, 2019
73c8cfe
fix: Not initalized integration
HazAT Nov 19, 2019
b62ea41
fix: Use scope instead of configureScope
HazAT Nov 20, 2019
3e28014
fix: Scope
HazAT Nov 20, 2019
707e622
feat: Add data before finish span
HazAT Nov 20, 2019
75e71fe
fix: Remove unused options
HazAT Nov 20, 2019
fa506ce
feat: Move Hub and Span to apm package
HazAT Nov 20, 2019
d8c7574
fix: Node build
HazAT Nov 20, 2019
dcf4c7f
meta: Cleanup
HazAT Nov 21, 2019
5116935
feat: Refactor to use global extension hub method
HazAT Nov 21, 2019
856dbd5
ref: Move code into tracing integration
HazAT Nov 21, 2019
b41142c
feat: Add shouldCreateSpanForRequest option
HazAT Nov 21, 2019
b34bcf8
feat: Add fetch tracking
HazAT Nov 21, 2019
ee0b17b
ref: Use correct SpanStatus types according to spec
kamilogorek Nov 26, 2019
bc17f87
Merge branch 'master' into apm
HazAT Nov 27, 2019
ea23290
feat: Move instrumentation and dsn to utils
HazAT Nov 27, 2019
e4d605d
feat: Auto status code, Fix idle navigation transaction
HazAT Nov 27, 2019
9cc5548
feat: Readme, lint, changelog
HazAT Nov 27, 2019
7d5d3f2
fix: Dont clash between span and scope trace context data
kamilogorek Dec 2, 2019
073920f
meta: Docs for options
HazAT Dec 2, 2019
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- [hub] feat: Add more span functions (#2161)
- [integrations] feat: Change `Tracing` integration (#2161)
- [browser] feat: Refactor breadcrumbs integration to allow for custom handlers

## 5.9.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build:es5": "lerna run --stream --concurrency 1 --sort build:es5",
"build:esm": "lerna run --stream --concurrency 1 --sort build:esm",
"build:watch": "lerna run build:watch --stream --no-sort --concurrency 9999",
"clean": "lerna run --stream clean",
"clean": "lerna run --stream clean && lerna clean --yes",
"fix": "lerna run --stream --concurrency 1 fix",
"link:yarn": "lerna run --stream --concurrency 1 link:yarn",
"lint": "lerna run --stream --concurrency 1 lint",
Expand Down
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"rollup": "^1.10.1",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-license": "^0.8.1",
"rollup-plugin-modify": "^3.0.0",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.21.0",
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export {
setTag,
setTags,
setUser,
startSpan,
Span,
withScope,
} from '@sentry/core';
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DsnLike } from '@sentry/types';
import { urlEncode } from '@sentry/utils';
import { timestampWithMs, urlEncode } from '@sentry/utils';

import { Dsn } from './dsn';

Expand Down Expand Up @@ -28,7 +28,7 @@ export class API {
public getStoreEndpointWithUrlEncodedAuth(): string {
const dsn = this._dsnObject;
const auth = {
sentry_key: dsn.user,
sentry_key: dsn.user, // sentry_key is currently used in tracing integration to identify internal sentry requests
sentry_version: SENTRY_API_VERSION,
};
// Auth is intentionally sent as part of query string (NOT as custom HTTP header)
Expand All @@ -54,7 +54,7 @@ export class API {
public getRequestHeaders(clientName: string, clientVersion: string): { [key: string]: string } {
const dsn = this._dsnObject;
const header = [`Sentry sentry_version=${SENTRY_API_VERSION}`];
header.push(`sentry_timestamp=${new Date().getTime()}`);
header.push(`sentry_timestamp=${timestampWithMs()}`); // TODO: This can be removed
header.push(`sentry_client=${clientName}/${clientVersion}`);
header.push(`sentry_key=${dsn.user}`);
if (dsn.pass) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
setTag,
setTags,
setUser,
startSpan,
withScope,
} from '@sentry/minimal';
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, Scope, Span } from '@sentry/hub';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ describe('API', () => {
expect(new API(dsnPublic).getRequestHeaders('a', '1.0')).toMatchObject({
'Content-Type': 'application/json',
'X-Sentry-Auth': expect.stringMatching(
/^Sentry sentry_version=\d, sentry_timestamp=\d+, sentry_client=a\/1\.0, sentry_key=abc$/,
/^Sentry sentry_version=\d, sentry_timestamp=\d+\.\d+, sentry_client=a\/1\.0, sentry_key=abc$/,
),
});

expect(new API(legacyDsn).getRequestHeaders('a', '1.0')).toMatchObject({
'Content-Type': 'application/json',
'X-Sentry-Auth': expect.stringMatching(
/^Sentry sentry_version=\d, sentry_timestamp=\d+, sentry_client=a\/1\.0, sentry_key=abc, sentry_secret=123$/,
/^Sentry sentry_version=\d, sentry_timestamp=\d+\.\d+, sentry_client=a\/1\.0, sentry_key=abc, sentry_secret=123$/,
),
});
});
Expand Down
62 changes: 57 additions & 5 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ import {
Integration,
IntegrationClass,
Severity,
SpanContext,
User,
} from '@sentry/types';
import { consoleSandbox, dynamicRequire, getGlobalObject, isNodeEnv, logger, uuid4 } from '@sentry/utils';
import {
consoleSandbox,
dynamicRequire,
getGlobalObject,
isNodeEnv,
logger,
timestampWithMs,
uuid4,
} from '@sentry/utils';

import { Carrier, Layer } from './interfaces';
import { Scope } from './scope';
import { Span } from './span';

declare module 'domain' {
export let active: Domain;
Expand All @@ -25,6 +35,14 @@ declare module 'domain' {
}
}

/**
* Checks whether given value is instance of Span
* @param span value to check
*/
function isSpanInstance(span: unknown): span is Span {
return span instanceof Span;
}

/**
* API compatibility version of this hub.
*
Expand Down Expand Up @@ -251,7 +269,7 @@ export class Hub implements HubInterface {
return;
}

const timestamp = new Date().getTime() / 1000;
const timestamp = timestampWithMs();
const mergedBreadcrumb = { timestamp, ...breadcrumb };
const finalBreadcrumb = beforeBreadcrumb
? (consoleSandbox(() => beforeBreadcrumb(mergedBreadcrumb, hint)) as Breadcrumb | null)
Expand Down Expand Up @@ -372,9 +390,9 @@ export class Hub implements HubInterface {
* @inheritDoc
*/
public traceHeaders(): { [key: string]: string } {
const top = this.getStackTop();
if (top.scope && top.client) {
const span = top.scope.getSpan();
const scope = this.getScope();
if (scope) {
const span = scope.getSpan();
if (span) {
return {
'sentry-trace': span.toTraceparent(),
Expand All @@ -383,6 +401,40 @@ export class Hub implements HubInterface {
}
return {};
}

/**
* @inheritDoc
*/
public startSpan(spanOrSpanContext?: Span | SpanContext, forceNoChild: boolean = false): Span {
const scope = this.getScope();
const client = this.getClient();
let span;

if (!isSpanInstance(spanOrSpanContext) && !forceNoChild) {
if (scope) {
const parentSpan = scope.getSpan();
if (parentSpan) {
span = parentSpan.child(spanOrSpanContext);
}
}
}

if (!isSpanInstance(span)) {
span = new Span(spanOrSpanContext, this);
}

if (span.sampled === undefined && span.transaction !== undefined) {
const sampleRate = (client && client.getOptions().tracesSampleRate) || 0;
span.sampled = Math.random() < sampleRate;
}

if (span.sampled) {
const experimentsOptions = (client && client.getOptions()._experiments) || {};
span.initFinishedSpans(experimentsOptions.maxSpans);
}

return span;
}
}

/** Returns the global shim registry. */
Expand Down
14 changes: 2 additions & 12 deletions packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Breadcrumb, Event, EventHint, EventProcessor, Scope as ScopeInterface, Severity, User } from '@sentry/types';
import { getGlobalObject, isThenable, normalize, SyncPromise } from '@sentry/utils';
import { getGlobalObject, isThenable, normalize, SyncPromise, timestampWithMs } from '@sentry/utils';

import { Span } from './span';

Expand Down Expand Up @@ -200,16 +200,6 @@ export class Scope implements ScopeInterface {
return this;
}

/**
* @inheritDoc
*/
public startSpan(parentSpan?: Span): Span {
const span = new Span();
span.setParent(parentSpan);
this.setSpan(span);
return span;
}

/**
* Internal getter for Span, used in Hub.
* @hidden
Expand Down Expand Up @@ -260,7 +250,7 @@ export class Scope implements ScopeInterface {
* @inheritDoc
*/
public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this {
const timestamp = new Date().getTime() / 1000;
const timestamp = timestampWithMs();
const mergedBreadcrumb = { timestamp, ...breadcrumb };

this._breadcrumbs =
Expand Down
Loading