@pocket-tools/tracing 1.7.5 → 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.
- package/.turbo/turbo-build.log +7 -7
- package/.turbo/turbo-semantic-release.log +67 -65
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +112 -3
- package/dist/index.mjs +121 -6
- package/package.json +5 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[33mCJS[39m [33mYou have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin[39m
|
|
12
12
|
[33mESM[39m [33mYou have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin[39m
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.60 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 105ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m9.41 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 112ms
|
|
17
17
|
[34mDTS[39m Build start
|
|
18
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 8390ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m557.00 B[39m
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m557.00 B[39m
|
|
@@ -14,75 +14,77 @@
|
|
|
14
14
|
[34mESM[39m Build start
|
|
15
15
|
[33mCJS[39m [33mYou have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin[39m
|
|
16
16
|
[33mESM[39m [33mYou have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin[39m
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m9.41 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 181ms
|
|
19
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.60 KB[39m
|
|
20
|
+
[32mCJS[39m ⚡️ Build success in 181ms
|
|
21
21
|
[34mDTS[39m Build start
|
|
22
|
-
[32mDTS[39m ⚡️ Build success in
|
|
23
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
24
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
+
[32mDTS[39m ⚡️ Build success in 8139ms
|
|
23
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m557.00 B[39m
|
|
24
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m557.00 B[39m
|
|
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
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
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
|
-
[
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
[
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
|
154
|
+
textMapPropagator: new import_core.CompositePropagator({
|
|
155
|
+
propagators: [new import_propagator_aws_xray.AWSXRayPropagator(), new import_opentelemetry.SentryPropagator()]
|
|
156
|
+
}),
|
|
152
157
|
instrumentations,
|
|
153
|
-
sampler:
|
|
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 {
|
|
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 {
|
|
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
|
|
134
|
+
textMapPropagator: new CompositePropagator({
|
|
135
|
+
propagators: [new AWSXRayPropagator(), new SentryPropagator()]
|
|
136
|
+
}),
|
|
126
137
|
instrumentations,
|
|
127
|
-
sampler:
|
|
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.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "Utilities for tracing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tracing"
|
|
@@ -87,9 +87,10 @@
|
|
|
87
87
|
"@opentelemetry/semantic-conventions": "1.27.0",
|
|
88
88
|
"@opentelemetry/winston-transport": "0.6.0",
|
|
89
89
|
"@prisma/instrumentation": "5.19.1",
|
|
90
|
-
"@sentry/node": "8.
|
|
91
|
-
"@sentry/opentelemetry": "8.
|
|
92
|
-
"tslib": "2.7.0"
|
|
90
|
+
"@sentry/node": "8.34.0",
|
|
91
|
+
"@sentry/opentelemetry": "8.34.0",
|
|
92
|
+
"tslib": "2.7.0",
|
|
93
|
+
"unleash-client": "6.1.1"
|
|
93
94
|
},
|
|
94
95
|
"devDependencies": {
|
|
95
96
|
"@jest/globals": "29.7.0",
|