Skip to content

Commit 68bf926

Browse files
committed
feat(opentelemetry): Add new @sentry/opentelemetry package
Apply suggestions from code review Co-authored-by: Abhijeet Prasad <[email protected]> PR feedback PR feedback: Expose proper `setupGlobalHub` method pr feedback & new release docs
1 parent df08e8f commit 68bf926

File tree

90 files changed

+3618
-962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3618
-962
lines changed

.craft.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ targets:
2424
- name: npm
2525
id: '@sentry/replay'
2626
includeNames: /^sentry-replay-\d.*\.tgz$/
27+
## 1.6. OpenTelemetry package
28+
- name: npm
29+
id: '@sentry/opentelemetry'
30+
includeNames: /^sentry-opentelemetry-\d.*\.tgz$/
2731

2832
## 2. Browser & Node SDKs
2933
- name: npm

docs/new-sdk-release-checklist.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ This page serves as a checklist of what to do when releasing a new SDK for the f
4747

4848
- [ ] Make sure it is added to `bundlePlugins.ts:makeTSPlugin` as `paths`, otherwise it will not be ES5 transpiled correctly for CDN builds.
4949

50+
- [ ] Make sure it is added to the [Verdaccio config](https://github.com/getsentry/sentry-javascript/blob/develop/packages/e2e-tests/verdaccio-config/config.yaml) for the E2E tests
51+
5052
## Cutting the Release
5153

5254
When you’re ready to make the first release, there are a couple of steps that need to be performed in the **correct order**. Note that you can prepare the PRs at any time but the **merging oder** is important:
@@ -56,7 +58,7 @@ When you’re ready to make the first release, there are a couple of steps that
5658
### Before the Release:
5759

5860
- [ ] 1) If not yet done, be sure to remove the `private: true` property from your SDK’s `package.json`. Additionally, ensure that `"publishConfig": {"access": "public"}` is set.
59-
- [ ] 2) Make sure that the new SDK is **not added** in`[craft.yml](https://github.com/getsentry/sentry-javascript/blob/master/.craft.yml)` as a target for the **Sentry release registry**\
61+
- [ ] 2) Make sure that the new SDK is **not added** in`[craft.yml](https://github.com/getsentry/sentry-javascript/blob/develop/.craft.yml)` as a target for the **Sentry release registry**\
6062
*Once this is added, craft will try to publish an entry in the next release which does not work and caused failed release runs in the past*
6163
- [ ] 3) Add an `npm` target in `craft.yml` for the new package. Make sure to insert it in the right place, after all the Sentry dependencies of your package but before packages that depend on your new package (if applicable).
6264
```yml
@@ -74,7 +76,7 @@ When you’re ready to make the first release, there are a couple of steps that
7476
You have to fork this repo and PR the files from your fork to the main repo \
7577
[Example PR](https://github.com/getsentry/sentry-release-registry/pull/80) from the Svelte SDK
7678
77-
- [ ] 2) Add an entry to `[craft.yml](https://github.com/getsentry/sentry-javascript/blob/master/.craft.yml)` to add releases of your SDK to the Sentry release registry \
79+
- [ ] 2) Add an entry to [craft.yml](https://github.com/getsentry/sentry-javascript/blob/develop/.craft.yml) to add releases of your SDK to the Sentry release registry \
7880
[Example PR](https://github.com/getsentry/sentry-javascript/pull/5547) from the Svelte SDK \
7981
*Subsequent releases will now be added automatically to the registry*
8082

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"packages/node-integration-tests",
6262
"packages/node-experimental",
6363
"packages/opentelemetry-node",
64+
"packages/opentelemetry",
6465
"packages/react",
6566
"packages/remix",
6667
"packages/replay",

packages/e2e-tests/verdaccio-config/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ packages:
122122
unpublish: $all
123123
# proxy: npmjs # Don't proxy for E2E tests!
124124

125+
'@sentry/opentelemetry':
126+
access: $all
127+
publish: $all
128+
unpublish: $all
129+
# proxy: npmjs # Don't proxy for E2E tests!
130+
125131
'@sentry/react':
126132
access: $all
127133
publish: $all

packages/node-experimental/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const span = Sentry.startSpan({ description: 'non-active span' });
8282

8383
doSomethingSlow();
8484

85-
span?.finish();
85+
span.finish();
8686
```
8787

8888
Finally you can also get the currently active span, if you need to do more with it:

packages/node-experimental/package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
},
2525
"dependencies": {
2626
"@opentelemetry/api": "~1.6.0",
27-
"@opentelemetry/context-async-hooks": "~1.17.0",
28-
"@opentelemetry/core": "~1.17.0",
29-
"@opentelemetry/instrumentation": "~0.43.0",
30-
"@opentelemetry/instrumentation-express": "~0.33.1",
31-
"@opentelemetry/instrumentation-fastify": "~0.32.3",
32-
"@opentelemetry/instrumentation-graphql": "~0.35.1",
33-
"@opentelemetry/instrumentation-http": "~0.43.0",
34-
"@opentelemetry/instrumentation-mongodb": "~0.37.0",
35-
"@opentelemetry/instrumentation-mongoose": "~0.33.1",
36-
"@opentelemetry/instrumentation-mysql": "~0.34.1",
37-
"@opentelemetry/instrumentation-mysql2": "~0.34.1",
38-
"@opentelemetry/instrumentation-nestjs-core": "~0.33.1",
39-
"@opentelemetry/instrumentation-pg": "~0.36.1",
40-
"@opentelemetry/resources": "~1.17.0",
41-
"@opentelemetry/sdk-trace-base": "~1.17.0",
42-
"@opentelemetry/semantic-conventions": "~1.17.0",
43-
"@prisma/instrumentation": "~5.3.1",
27+
"@opentelemetry/core": "~1.17.1",
28+
"@opentelemetry/context-async-hooks": "~1.17.1",
29+
"@opentelemetry/instrumentation": "0.44.0",
30+
"@opentelemetry/instrumentation-express": "0.33.2",
31+
"@opentelemetry/instrumentation-fastify": "0.32.3",
32+
"@opentelemetry/instrumentation-graphql": "0.35.2",
33+
"@opentelemetry/instrumentation-http": "0.44.0",
34+
"@opentelemetry/instrumentation-mongodb": "0.37.1",
35+
"@opentelemetry/instrumentation-mongoose": "0.33.2",
36+
"@opentelemetry/instrumentation-mysql": "0.34.2",
37+
"@opentelemetry/instrumentation-mysql2": "0.34.2",
38+
"@opentelemetry/instrumentation-nestjs-core": "0.33.2",
39+
"@opentelemetry/instrumentation-pg": "0.36.2",
40+
"@opentelemetry/resources": "~1.17.1",
41+
"@opentelemetry/sdk-trace-base": "~1.17.1",
42+
"@opentelemetry/semantic-conventions": "~1.17.1",
43+
"@prisma/instrumentation": "5.4.2",
4444
"@sentry/core": "7.74.1",
4545
"@sentry/node": "7.74.1",
46-
"@sentry/opentelemetry-node": "7.74.1",
46+
"@sentry/opentelemetry": "7.74.1",
4747
"@sentry/types": "7.74.1",
4848
"@sentry/utils": "7.74.1",
4949
"opentelemetry-instrumentation-fetch-node": "1.1.0"

packages/node-experimental/src/constants.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/node-experimental/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ export { init } from './sdk/init';
1111
export { INTEGRATIONS as Integrations };
1212
export { getAutoPerformanceIntegrations } from './integrations/getAutoPerformanceIntegrations';
1313
export * as Handlers from './sdk/handlers';
14-
export * from './sdk/trace';
15-
export { getActiveSpan } from './utils/getActiveSpan';
16-
export { getCurrentHub, getHubFromCarrier } from './sdk/hub';
1714
export type { Span } from './types';
1815

16+
export { startSpan, startInactiveSpan, getCurrentHub, getActiveSpan } from '@sentry/opentelemetry';
17+
1918
export {
2019
makeNodeTransport,
2120
defaultStackParser,

packages/node-experimental/src/integrations/http.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import { SpanKind } from '@opentelemetry/api';
33
import { registerInstrumentations } from '@opentelemetry/instrumentation';
44
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
55
import { hasTracingEnabled, isSentryRequestUrl } from '@sentry/core';
6+
import { _INTERNAL, getCurrentHub, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
67
import type { EventProcessor, Hub, Integration } from '@sentry/types';
78
import { stringMatchesSomePattern } from '@sentry/utils';
89
import type { ClientRequest, IncomingMessage, ServerResponse } from 'http';
910

10-
import { OTEL_ATTR_ORIGIN } from '../constants';
11-
import { setSpanMetadata } from '../opentelemetry/spanData';
12-
import type { NodeExperimentalClient } from '../sdk/client';
13-
import { getCurrentHub } from '../sdk/hub';
14-
import { getRequestSpanData } from '../utils/getRequestSpanData';
11+
import type { NodeExperimentalClient } from '../types';
12+
import { addOriginToSpan } from '../utils/addOriginToSpan';
1513
import { getRequestUrl } from '../utils/getRequestUrl';
16-
import { getSpanKind } from '../utils/getSpanKind';
1714

1815
interface HttpOptions {
1916
/**
@@ -148,7 +145,7 @@ export class Http implements Integration {
148145

149146
/** Update the span with data we need. */
150147
private _updateSpan(span: Span, request: ClientRequest | IncomingMessage): void {
151-
span.setAttribute(OTEL_ATTR_ORIGIN, 'auto.http.otel.http');
148+
addOriginToSpan(span, 'auto.http.otel.http');
152149

153150
if (getSpanKind(span) === SpanKind.SERVER) {
154151
setSpanMetadata(span, { request });
@@ -161,7 +158,7 @@ export class Http implements Integration {
161158
return;
162159
}
163160

164-
const data = getRequestSpanData(span);
161+
const data = _INTERNAL.getRequestSpanData(span);
165162
getCurrentHub().addBreadcrumb(
166163
{
167164
category: 'http',

packages/node-experimental/src/integrations/node-fetch.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import type { Span } from '@opentelemetry/api';
22
import { SpanKind } from '@opentelemetry/api';
33
import type { Instrumentation } from '@opentelemetry/instrumentation';
44
import { hasTracingEnabled } from '@sentry/core';
5+
import { _INTERNAL, getCurrentHub, getSpanKind } from '@sentry/opentelemetry';
56
import type { Integration } from '@sentry/types';
67
import { FetchInstrumentation } from 'opentelemetry-instrumentation-fetch-node';
78

8-
import { OTEL_ATTR_ORIGIN } from '../constants';
9-
import type { NodeExperimentalClient } from '../sdk/client';
10-
import { getCurrentHub } from '../sdk/hub';
11-
import { getRequestSpanData } from '../utils/getRequestSpanData';
12-
import { getSpanKind } from '../utils/getSpanKind';
9+
import type { NodeExperimentalClient } from '../types';
10+
import { addOriginToSpan } from '../utils/addOriginToSpan';
1311
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
1412

1513
interface NodeFetchOptions {
@@ -101,7 +99,7 @@ export class NodeFetch extends NodePerformanceIntegration<NodeFetchOptions> impl
10199

102100
/** Update the span with data we need. */
103101
private _updateSpan(span: Span): void {
104-
span.setAttribute(OTEL_ATTR_ORIGIN, 'auto.http.otel.node_fetch');
102+
addOriginToSpan(span, 'auto.http.otel.node_fetch');
105103
}
106104

107105
/** Add a breadcrumb for outgoing requests. */
@@ -110,7 +108,7 @@ export class NodeFetch extends NodePerformanceIntegration<NodeFetchOptions> impl
110108
return;
111109
}
112110

113-
const data = getRequestSpanData(span);
111+
const data = _INTERNAL.getRequestSpanData(span);
114112
getCurrentHub().addBreadcrumb({
115113
category: 'http',
116114
data: {

packages/node-experimental/src/opentelemetry/contextManager.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/node-experimental/src/opentelemetry/spanProcessor.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)