@pocket-tools/tracing 1.7.6 → 1.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,11 +10,11 @@
10
10
  ESM Build start
11
11
  CJS You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin
12
12
  ESM You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin
13
- CJS dist/index.js 7.93 KB
14
- CJS ⚡️ Build success in 122ms
15
- ESM dist/index.mjs 5.76 KB
16
- ESM ⚡️ Build success in 122ms
13
+ CJS dist/index.js 11.60 KB
14
+ CJS ⚡️ Build success in 105ms
15
+ ESM dist/index.mjs 9.41 KB
16
+ ESM ⚡️ Build success in 112ms
17
17
  DTS Build start
18
- DTS ⚡️ Build success in 9032ms
19
- DTS dist/index.d.ts 549.00 B
20
- DTS dist/index.d.mts 549.00 B
18
+ DTS ⚡️ Build success in 8390ms
19
+ DTS dist/index.d.ts 557.00 B
20
+ DTS dist/index.d.mts 557.00 B
@@ -14,75 +14,77 @@
14
14
  ESM Build start
15
15
  CJS You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin
16
16
  ESM You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin
17
- CJS dist/index.js 7.93 KB
18
- CJS ⚡️ Build success in 130ms
19
- ESM dist/index.mjs 5.76 KB
20
- ESM ⚡️ Build success in 133ms
17
+ ESM dist/index.mjs 9.41 KB
18
+ ESM ⚡️ Build success in 181ms
19
+ CJS dist/index.js 11.60 KB
20
+ CJS ⚡️ Build success in 181ms
21
21
  DTS Build start
22
- DTS ⚡️ Build success in 6282ms
23
- DTS dist/index.d.ts 549.00 B
24
- DTS dist/index.d.mts 549.00 B
22
+ DTS ⚡️ Build success in 8139ms
23
+ DTS dist/index.d.ts 557.00 B
24
+ DTS dist/index.d.mts 557.00 B
25
25
 
26
26
  > @pocket-tools/tracing@0.0.0-development semantic-release /home/runner/work/pocket-monorepo/pocket-monorepo/packages/tracing
27
27
  > semantic-release
28
28
 
29
- [10:14:23 PM] [semantic-release] › ℹ Running semantic-release version 24.1.0
30
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/npm"
31
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/github"
32
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "prepare" from "@semantic-release/npm"
33
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/npm"
34
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/github"
35
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/npm"
36
- [10:14:24 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/github"
37
- [10:14:27 PM] [semantic-release] › ✔ Run automated release from branch main on repository git+https://github.com/Pocket/pocket-monorepo.git
38
- [10:14:27 PM] [semantic-release] › ✔ Allowed to push to the Git repository
39
- [10:14:27 PM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/npm"
40
- [10:14:27 PM] [semantic-release] [@semantic-release/npm] › ℹ Verify authentication for registry https://registry.npmjs.org/
41
- [10:14:27 PM] [semantic-release] [@semantic-release/npm] › ℹ Wrote NPM_TOKEN to /tmp/7fa1adbeb42857aae819140ecb00c519/.npmrc
29
+ [11:32:53 PM] [semantic-release] › ℹ Running semantic-release version 24.1.0
30
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/npm"
31
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/github"
32
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "prepare" from "@semantic-release/npm"
33
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/npm"
34
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/github"
35
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/npm"
36
+ [11:32:55 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/github"
37
+ [11:33:00 PM] [semantic-release] › ✔ Run automated release from branch main on repository git+https://github.com/Pocket/pocket-monorepo.git
38
+ [11:33:01 PM] [semantic-release] › ✔ Allowed to push to the Git repository
39
+ [11:33:01 PM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/npm"
40
+ [11:33:01 PM] [semantic-release] [@semantic-release/npm] › ℹ Verify authentication for registry https://registry.npmjs.org/
41
+ [11:33:01 PM] [semantic-release] [@semantic-release/npm] › ℹ Wrote NPM_TOKEN to /tmp/1eeff18a3ab33a955909b8c7f172a5d8/.npmrc
42
42
  pocket-npm
43
- [10:14:28 PM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/npm"
44
- [10:14:28 PM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/github"
45
- [10:14:28 PM] [semantic-release] [@semantic-release/github] › ℹ Verify GitHub authentication (https://api.github.com)
46
- [10:14:28 PM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/github"
47
- [10:14:28 PM] [semantic-release] › ℹ Found git tag @pocket-tools/tracing-v1.7.5 associated with version 1.7.5 on branch main
48
- [10:14:28 PM] [semantic-release] › ℹ Found 5 commits since last release
49
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
50
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
51
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Found 1 commits for package @pocket-tools/tracing since last release
52
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Analyzing commit: fix(deps): update sentry-javascript monorepo to v8.34.0 (#818)
43
+ [11:33:02 PM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/npm"
44
+ [11:33:02 PM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/github"
45
+ [11:33:02 PM] [semantic-release] [@semantic-release/github] › ℹ Verify GitHub authentication (https://api.github.com)
46
+ [11:33:02 PM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/github"
47
+ [11:33:02 PM] [semantic-release] › ℹ Found git tag @pocket-tools/tracing-v1.7.6 associated with version 1.7.6 on branch main
48
+ [11:33:02 PM] [semantic-release] › ℹ Found 1 commits since last release
49
+ [11:33:02 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
50
+ [11:33:02 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
51
+ [11:33:02 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Found 1 commits for package @pocket-tools/tracing since last release
52
+ [11:33:02 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Analyzing commit: fix(otel): ensure sentry inits first (#809)
53
53
 
54
- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
55
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ The release type for the commit is patch
56
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] ℹ Analysis of 1 commits complete: patch release
57
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
58
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
59
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
60
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/release-notes-generator" does not provide step "analyzeCommits"
61
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
62
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
63
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/npm" does not provide step "analyzeCommits"
64
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
65
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
66
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/github" does not provide step "analyzeCommits"
67
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
68
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
69
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
70
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
71
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
72
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
73
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
74
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
75
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
76
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
77
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
78
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
79
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
80
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
81
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
82
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
83
- [10:14:28 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
84
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
85
- [10:14:28 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
86
- [10:14:28 PM] [semantic-release] › ℹ The next release version is 1.7.6
87
- [10:14:28 PM] [semantic-release] › Start step "generateNotes" of plugin "[Function: semantic-release-monorepo]"
88
- [10:14:28 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/commit-analyzer" does not provide step "generateNotes"
54
+ * fix(otel): working on removing double trace ids from outgoing requests
55
+
56
+ * fix(otel): ensure sentry always boots first for request isolation
57
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ The release type for the commit is patch
58
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] Analysis of 1 commits complete: patch release
59
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
60
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
61
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
62
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/release-notes-generator" does not provide step "analyzeCommits"
63
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
64
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
65
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/npm" does not provide step "analyzeCommits"
66
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
67
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
68
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/github" does not provide step "analyzeCommits"
69
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
70
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
71
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
72
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
73
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
74
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
75
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
76
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
77
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
78
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
79
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
80
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
81
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
82
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
83
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
84
+ [11:33:03 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
85
+ [11:33:03 PM] [semantic-release] › Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
86
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
87
+ [11:33:03 PM] [semantic-release] › Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
88
+ [11:33:03 PM] [semantic-release] › ℹ The next release version is 1.7.7
89
+ [11:33:03 PM] [semantic-release] › ℹ Start step "generateNotes" of plugin "[Function: semantic-release-monorepo]"
90
+ [11:33:03 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/commit-analyzer" does not provide step "generateNotes"
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { NodeClient } from '@sentry/node';
1
+ import { Unleash } from 'unleash-client';
2
2
 
3
3
  declare enum AdditionalInstrumentation {
4
4
  KNEX = "KNEX",
@@ -11,7 +11,8 @@ type TracingConfig = {
11
11
  graphQLDepth?: number;
12
12
  url?: string;
13
13
  protocol?: 'GRPC' | 'HTTP';
14
- sentry: NodeClient | undefined;
14
+ unleash: Unleash;
15
+ flagName?: string;
15
16
  additionalInstrumentations?: AdditionalInstrumentation[];
16
17
  };
17
18
  declare function nodeSDKBuilder(config: TracingConfig): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NodeClient } from '@sentry/node';
1
+ import { Unleash } from 'unleash-client';
2
2
 
3
3
  declare enum AdditionalInstrumentation {
4
4
  KNEX = "KNEX",
@@ -11,7 +11,8 @@ type TracingConfig = {
11
11
  graphQLDepth?: number;
12
12
  url?: string;
13
13
  protocol?: 'GRPC' | 'HTTP';
14
- sentry: NodeClient | undefined;
14
+ unleash: Unleash;
15
+ flagName?: string;
15
16
  additionalInstrumentations?: AdditionalInstrumentation[];
16
17
  };
17
18
  declare function nodeSDKBuilder(config: TracingConfig): Promise<void>;
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ var Sentry = __toESM(require("@sentry/node"));
54
54
  var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
55
55
  var import_propagator_aws_xray = require("@opentelemetry/propagator-aws-xray");
56
56
  var import_id_generator_aws_xray = require("@opentelemetry/id-generator-aws-xray");
57
+ var import_core = require("@opentelemetry/core");
57
58
  var AdditionalInstrumentation = /* @__PURE__ */ ((AdditionalInstrumentation2) => {
58
59
  AdditionalInstrumentation2["KNEX"] = "KNEX";
59
60
  AdditionalInstrumentation2["PRISMA"] = "PRISMA";
@@ -66,10 +67,12 @@ var additionalInstrumentationConstructors = {
66
67
  var tracingDefaults = {
67
68
  serviceName: "unknown",
68
69
  release: "unknown",
69
- sentry: void 0,
70
70
  graphQLDepth: 8,
71
71
  url: "http://localhost:4318",
72
72
  protocol: "HTTP",
73
+ unleash: {},
74
+ // no-op cause its required in the config
75
+ flagName: "perm.backend.sentry-trace-sampler-rate",
73
76
  additionalInstrumentations: []
74
77
  };
75
78
  function awaitAttributes(detector) {
@@ -148,9 +151,19 @@ async function nodeSDKBuilder(config) {
148
151
  );
149
152
  });
150
153
  const sdk = new import_sdk_node.NodeSDK({
151
- textMapPropagator: new import_propagator_aws_xray.AWSXRayPropagator(),
154
+ textMapPropagator: new import_core.CompositePropagator({
155
+ propagators: [new import_propagator_aws_xray.AWSXRayPropagator(), new import_opentelemetry.SentryPropagator()]
156
+ }),
152
157
  instrumentations,
153
- sampler: config.sentry ? new import_sdk_trace_base.ParentBasedSampler({ root: new import_opentelemetry.SentrySampler(config.sentry) }) : void 0,
158
+ sampler: new SentryParentSampler({
159
+ root: new import_sdk_trace_base.ParentBasedSampler({
160
+ root: new UnleashSampler({
161
+ unleash: config.unleash,
162
+ flagName: config.flagName
163
+ // will never be null cause of defaults
164
+ })
165
+ })
166
+ }),
154
167
  contextManager: new Sentry.SentryContextManager(),
155
168
  resource: _resource,
156
169
  idGenerator: new import_id_generator_aws_xray.AWSXRayIdGenerator(),
@@ -178,6 +191,102 @@ async function nodeSDKBuilder(config) {
178
191
  ).finally(() => import_process.default.exit(0));
179
192
  });
180
193
  }
194
+ var UnleashSampler = class _UnleashSampler {
195
+ constructor(config) {
196
+ this._flagName = config.flagName;
197
+ this._unleash = config.unleash;
198
+ this.setRatio(0);
199
+ }
200
+ /**
201
+ * Checks whether span needs to be created and tracked.
202
+ *
203
+ * @param context Parent Context which may contain a span.
204
+ * @param traceId of the span to be created. It can be different from the
205
+ * traceId in the {@link SpanContext}. Typically in situations when the
206
+ * span to be created starts a new trace.
207
+ * @param spanName of the span to be created.
208
+ * @param spanKind of the span to be created.
209
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
210
+ * @param links Collection of links that will be associated with the Span to
211
+ * be created. Typically useful for batch operations.
212
+ * @returns a {@link SamplingResult}.
213
+ */
214
+ shouldSample(context, traceId, spanName, spanKind, attributes, links) {
215
+ this.updateFlagValue();
216
+ return {
217
+ decision: (0, import_api.isValidTraceId)(traceId) && this._accumulate(traceId) < this._upperBound ? import_sdk_trace_base.SamplingDecision.RECORD_AND_SAMPLED : import_sdk_trace_base.SamplingDecision.NOT_RECORD
218
+ };
219
+ }
220
+ updateFlagValue() {
221
+ const variant = this._unleash.getVariant(this._flagName);
222
+ if (variant.payload != null) {
223
+ if (variant.payload.type === "number") {
224
+ this.setRatio(parseFloat(variant.payload.value));
225
+ } else {
226
+ this.setRatio(0);
227
+ }
228
+ } else {
229
+ this.setRatio(0);
230
+ }
231
+ }
232
+ setRatio(ratio) {
233
+ this._ratio = this._normalize(ratio);
234
+ this._upperBound = Math.floor(this._ratio * 4294967295);
235
+ }
236
+ toString() {
237
+ return _UnleashSampler.name;
238
+ }
239
+ _normalize(ratio) {
240
+ if (typeof ratio !== "number" || isNaN(ratio)) return 0;
241
+ return ratio >= 1 ? 1 : ratio <= 0 ? 0 : ratio;
242
+ }
243
+ _accumulate(traceId) {
244
+ let accumulation = 0;
245
+ for (let i = 0; i < traceId.length / 8; i++) {
246
+ const pos = i * 8;
247
+ const part = parseInt(traceId.slice(pos, pos + 8), 16);
248
+ accumulation = (accumulation ^ part) >>> 0;
249
+ }
250
+ return accumulation;
251
+ }
252
+ };
253
+ var SentryParentSampler = class _SentryParentSampler {
254
+ constructor(config) {
255
+ this._root = config.root;
256
+ }
257
+ /**
258
+ * Checks whether span needs to be created and tracked.
259
+ *
260
+ * @param context Parent Context which may contain a span.
261
+ * @param traceId of the span to be created. It can be different from the
262
+ * traceId in the {@link SpanContext}. Typically in situations when the
263
+ * span to be created starts a new trace.
264
+ * @param spanName of the span to be created.
265
+ * @param spanKind of the span to be created.
266
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
267
+ * @param links Collection of links that will be associated with the Span to
268
+ * be created. Typically useful for batch operations.
269
+ * @returns a {@link SamplingResult}.
270
+ */
271
+ shouldSample(context, traceId, spanName, spanKind, attributes, links) {
272
+ const decision = this._root.shouldSample(
273
+ context,
274
+ traceId,
275
+ spanName,
276
+ spanKind,
277
+ attributes,
278
+ links
279
+ );
280
+ return (0, import_opentelemetry.wrapSamplingDecision)({
281
+ decision: decision.decision,
282
+ context,
283
+ spanAttributes: attributes
284
+ });
285
+ }
286
+ toString() {
287
+ return _SentryParentSampler.name;
288
+ }
289
+ };
181
290
  // Annotate the CommonJS export names for ESM import in node:
182
291
  0 && (module.exports = {
183
292
  AdditionalInstrumentation,
package/dist/index.mjs CHANGED
@@ -1,7 +1,12 @@
1
1
  // src/tracing.ts
2
2
  import process from "process";
3
3
  import { NodeSDK, logs } from "@opentelemetry/sdk-node";
4
- import { DiagConsoleLogger, DiagLogLevel, diag } from "@opentelemetry/api";
4
+ import {
5
+ DiagConsoleLogger,
6
+ DiagLogLevel,
7
+ diag,
8
+ isValidTraceId
9
+ } from "@opentelemetry/api";
5
10
  import { KnexInstrumentation } from "@opentelemetry/instrumentation-knex";
6
11
  import { OTLPTraceExporter as HTTPOTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
7
12
  import { OTLPTraceExporter as GRPCOTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
@@ -13,7 +18,7 @@ import {
13
18
  ATTR_SERVICE_NAME,
14
19
  ATTR_SERVICE_VERSION
15
20
  } from "@opentelemetry/semantic-conventions";
16
- import { SentrySampler } from "@sentry/opentelemetry";
21
+ import { SentryPropagator, wrapSamplingDecision } from "@sentry/opentelemetry";
17
22
  import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
18
23
  import {
19
24
  envDetectorSync,
@@ -24,10 +29,12 @@ import { awsEcsDetectorSync } from "@opentelemetry/resource-detector-aws";
24
29
  import * as Sentry from "@sentry/node";
25
30
  import {
26
31
  BatchSpanProcessor,
27
- ParentBasedSampler
32
+ ParentBasedSampler,
33
+ SamplingDecision
28
34
  } from "@opentelemetry/sdk-trace-base";
29
35
  import { AWSXRayPropagator } from "@opentelemetry/propagator-aws-xray";
30
36
  import { AWSXRayIdGenerator } from "@opentelemetry/id-generator-aws-xray";
37
+ import { CompositePropagator } from "@opentelemetry/core";
31
38
  var AdditionalInstrumentation = /* @__PURE__ */ ((AdditionalInstrumentation2) => {
32
39
  AdditionalInstrumentation2["KNEX"] = "KNEX";
33
40
  AdditionalInstrumentation2["PRISMA"] = "PRISMA";
@@ -40,10 +47,12 @@ var additionalInstrumentationConstructors = {
40
47
  var tracingDefaults = {
41
48
  serviceName: "unknown",
42
49
  release: "unknown",
43
- sentry: void 0,
44
50
  graphQLDepth: 8,
45
51
  url: "http://localhost:4318",
46
52
  protocol: "HTTP",
53
+ unleash: {},
54
+ // no-op cause its required in the config
55
+ flagName: "perm.backend.sentry-trace-sampler-rate",
47
56
  additionalInstrumentations: []
48
57
  };
49
58
  function awaitAttributes(detector) {
@@ -122,9 +131,19 @@ async function nodeSDKBuilder(config) {
122
131
  );
123
132
  });
124
133
  const sdk = new NodeSDK({
125
- textMapPropagator: new AWSXRayPropagator(),
134
+ textMapPropagator: new CompositePropagator({
135
+ propagators: [new AWSXRayPropagator(), new SentryPropagator()]
136
+ }),
126
137
  instrumentations,
127
- sampler: config.sentry ? new ParentBasedSampler({ root: new SentrySampler(config.sentry) }) : void 0,
138
+ sampler: new SentryParentSampler({
139
+ root: new ParentBasedSampler({
140
+ root: new UnleashSampler({
141
+ unleash: config.unleash,
142
+ flagName: config.flagName
143
+ // will never be null cause of defaults
144
+ })
145
+ })
146
+ }),
128
147
  contextManager: new Sentry.SentryContextManager(),
129
148
  resource: _resource,
130
149
  idGenerator: new AWSXRayIdGenerator(),
@@ -152,6 +171,102 @@ async function nodeSDKBuilder(config) {
152
171
  ).finally(() => process.exit(0));
153
172
  });
154
173
  }
174
+ var UnleashSampler = class _UnleashSampler {
175
+ constructor(config) {
176
+ this._flagName = config.flagName;
177
+ this._unleash = config.unleash;
178
+ this.setRatio(0);
179
+ }
180
+ /**
181
+ * Checks whether span needs to be created and tracked.
182
+ *
183
+ * @param context Parent Context which may contain a span.
184
+ * @param traceId of the span to be created. It can be different from the
185
+ * traceId in the {@link SpanContext}. Typically in situations when the
186
+ * span to be created starts a new trace.
187
+ * @param spanName of the span to be created.
188
+ * @param spanKind of the span to be created.
189
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
190
+ * @param links Collection of links that will be associated with the Span to
191
+ * be created. Typically useful for batch operations.
192
+ * @returns a {@link SamplingResult}.
193
+ */
194
+ shouldSample(context, traceId, spanName, spanKind, attributes, links) {
195
+ this.updateFlagValue();
196
+ return {
197
+ decision: isValidTraceId(traceId) && this._accumulate(traceId) < this._upperBound ? SamplingDecision.RECORD_AND_SAMPLED : SamplingDecision.NOT_RECORD
198
+ };
199
+ }
200
+ updateFlagValue() {
201
+ const variant = this._unleash.getVariant(this._flagName);
202
+ if (variant.payload != null) {
203
+ if (variant.payload.type === "number") {
204
+ this.setRatio(parseFloat(variant.payload.value));
205
+ } else {
206
+ this.setRatio(0);
207
+ }
208
+ } else {
209
+ this.setRatio(0);
210
+ }
211
+ }
212
+ setRatio(ratio) {
213
+ this._ratio = this._normalize(ratio);
214
+ this._upperBound = Math.floor(this._ratio * 4294967295);
215
+ }
216
+ toString() {
217
+ return _UnleashSampler.name;
218
+ }
219
+ _normalize(ratio) {
220
+ if (typeof ratio !== "number" || isNaN(ratio)) return 0;
221
+ return ratio >= 1 ? 1 : ratio <= 0 ? 0 : ratio;
222
+ }
223
+ _accumulate(traceId) {
224
+ let accumulation = 0;
225
+ for (let i = 0; i < traceId.length / 8; i++) {
226
+ const pos = i * 8;
227
+ const part = parseInt(traceId.slice(pos, pos + 8), 16);
228
+ accumulation = (accumulation ^ part) >>> 0;
229
+ }
230
+ return accumulation;
231
+ }
232
+ };
233
+ var SentryParentSampler = class _SentryParentSampler {
234
+ constructor(config) {
235
+ this._root = config.root;
236
+ }
237
+ /**
238
+ * Checks whether span needs to be created and tracked.
239
+ *
240
+ * @param context Parent Context which may contain a span.
241
+ * @param traceId of the span to be created. It can be different from the
242
+ * traceId in the {@link SpanContext}. Typically in situations when the
243
+ * span to be created starts a new trace.
244
+ * @param spanName of the span to be created.
245
+ * @param spanKind of the span to be created.
246
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
247
+ * @param links Collection of links that will be associated with the Span to
248
+ * be created. Typically useful for batch operations.
249
+ * @returns a {@link SamplingResult}.
250
+ */
251
+ shouldSample(context, traceId, spanName, spanKind, attributes, links) {
252
+ const decision = this._root.shouldSample(
253
+ context,
254
+ traceId,
255
+ spanName,
256
+ spanKind,
257
+ attributes,
258
+ links
259
+ );
260
+ return wrapSamplingDecision({
261
+ decision: decision.decision,
262
+ context,
263
+ spanAttributes: attributes
264
+ });
265
+ }
266
+ toString() {
267
+ return _SentryParentSampler.name;
268
+ }
269
+ };
155
270
  export {
156
271
  AdditionalInstrumentation,
157
272
  nodeSDKBuilder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pocket-tools/tracing",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "description": "Utilities for tracing",
5
5
  "keywords": [
6
6
  "tracing"
@@ -89,7 +89,8 @@
89
89
  "@prisma/instrumentation": "5.19.1",
90
90
  "@sentry/node": "8.34.0",
91
91
  "@sentry/opentelemetry": "8.34.0",
92
- "tslib": "2.7.0"
92
+ "tslib": "2.7.0",
93
+ "unleash-client": "6.1.1"
93
94
  },
94
95
  "devDependencies": {
95
96
  "@jest/globals": "29.7.0",