@pocket-tools/tracing 1.7.6 → 1.7.8
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 +115 -3
- package/dist/index.mjs +124 -6
- package/package.json +3 -2
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
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.93 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 98ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m9.74 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 109ms
|
|
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 9996ms
|
|
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.74 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 154ms
|
|
19
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.93 KB[39m
|
|
20
|
+
[32mCJS[39m ⚡️ Build success in 158ms
|
|
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 8955ms
|
|
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
|
+
[4:34:36 PM] [semantic-release] › ℹ Running semantic-release version 24.1.0
|
|
30
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/npm"
|
|
31
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/github"
|
|
32
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "prepare" from "@semantic-release/npm"
|
|
33
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/npm"
|
|
34
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/github"
|
|
35
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/npm"
|
|
36
|
+
[4:34:37 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/github"
|
|
37
|
+
[4:34:48 PM] [semantic-release] › ✔ Run automated release from branch main on repository git+https://github.com/Pocket/pocket-monorepo.git
|
|
38
|
+
[4:34:48 PM] [semantic-release] › ✔ Allowed to push to the Git repository
|
|
39
|
+
[4:34:48 PM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/npm"
|
|
40
|
+
[4:34:48 PM] [semantic-release] [@semantic-release/npm] › ℹ Verify authentication for registry https://registry.npmjs.org/
|
|
41
|
+
[4:34:48 PM] [semantic-release] [@semantic-release/npm] › ℹ Wrote NPM_TOKEN to /tmp/bd28f8e5aa20b6ffc9298091e423cc89/.npmrc
|
|
42
42
|
pocket-npm
|
|
43
|
-
[
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
43
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/npm"
|
|
44
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/github"
|
|
45
|
+
[4:34:49 PM] [semantic-release] [@semantic-release/github] › ℹ Verify GitHub authentication (https://api.github.com)
|
|
46
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/github"
|
|
47
|
+
[4:34:49 PM] [semantic-release] › ℹ Found git tag @pocket-tools/tracing-v1.7.7 associated with version 1.7.7 on branch main
|
|
48
|
+
[4:34:49 PM] [semantic-release] › ℹ Found 1 commits since last release
|
|
49
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
50
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
|
|
51
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Found 1 commits for package @pocket-tools/tracing since last release
|
|
52
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Analyzing commit: fix(sentry): ensure sentry tagging checks body (#820)
|
|
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(sentry): ensure sentry tagging checks body
|
|
55
|
+
|
|
56
|
+
* fix(otel): improving otel to priotize XRay
|
|
57
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ The release type for the commit is patch
|
|
58
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Analysis of 1 commits complete: patch release
|
|
59
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
|
|
60
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
61
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
62
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/release-notes-generator" does not provide step "analyzeCommits"
|
|
63
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
64
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
65
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/npm" does not provide step "analyzeCommits"
|
|
66
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
67
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
68
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ Plugin "@semantic-release/github" does not provide step "analyzeCommits"
|
|
69
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
70
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
71
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
|
|
72
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
73
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
74
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
|
|
75
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
76
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
77
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
|
|
78
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
79
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
80
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
|
|
81
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
82
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
83
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
|
|
84
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
85
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
86
|
+
[4:34:49 PM] [semantic-release] [[Function: semantic-release-monorepo]] › ℹ No more plugins
|
|
87
|
+
[4:34:49 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
|
|
88
|
+
[4:34:49 PM] [semantic-release] › ℹ The next release version is 1.7.8
|
|
89
|
+
[4:34:49 PM] [semantic-release] › ℹ Start step "generateNotes" of plugin "[Function: semantic-release-monorepo]"
|
|
90
|
+
[4:34:49 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,22 @@ 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
|
+
// The Propogators are run in the order they are added, and since we want the AWSXRAY to win,
|
|
156
|
+
// it must come last because it writes the parent context "sampled" data from the trace into the contexts
|
|
157
|
+
// We Keep Sentry in here, because it adds data that Sentry needs, we just don't want it to control the sample value.
|
|
158
|
+
propagators: [new import_opentelemetry.SentryPropagator(), new import_propagator_aws_xray.AWSXRayPropagator()]
|
|
159
|
+
}),
|
|
152
160
|
instrumentations,
|
|
153
|
-
sampler:
|
|
161
|
+
sampler: new SentryParentSampler({
|
|
162
|
+
root: new import_sdk_trace_base.ParentBasedSampler({
|
|
163
|
+
root: new UnleashSampler({
|
|
164
|
+
unleash: config.unleash,
|
|
165
|
+
flagName: config.flagName
|
|
166
|
+
// will never be null cause of defaults
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
}),
|
|
154
170
|
contextManager: new Sentry.SentryContextManager(),
|
|
155
171
|
resource: _resource,
|
|
156
172
|
idGenerator: new import_id_generator_aws_xray.AWSXRayIdGenerator(),
|
|
@@ -178,6 +194,102 @@ async function nodeSDKBuilder(config) {
|
|
|
178
194
|
).finally(() => import_process.default.exit(0));
|
|
179
195
|
});
|
|
180
196
|
}
|
|
197
|
+
var UnleashSampler = class _UnleashSampler {
|
|
198
|
+
constructor(config) {
|
|
199
|
+
this._flagName = config.flagName;
|
|
200
|
+
this._unleash = config.unleash;
|
|
201
|
+
this.setRatio(0);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Checks whether span needs to be created and tracked.
|
|
205
|
+
*
|
|
206
|
+
* @param context Parent Context which may contain a span.
|
|
207
|
+
* @param traceId of the span to be created. It can be different from the
|
|
208
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
209
|
+
* span to be created starts a new trace.
|
|
210
|
+
* @param spanName of the span to be created.
|
|
211
|
+
* @param spanKind of the span to be created.
|
|
212
|
+
* @param attributes Initial set of SpanAttributes for the Span being constructed.
|
|
213
|
+
* @param links Collection of links that will be associated with the Span to
|
|
214
|
+
* be created. Typically useful for batch operations.
|
|
215
|
+
* @returns a {@link SamplingResult}.
|
|
216
|
+
*/
|
|
217
|
+
shouldSample(context, traceId, spanName, spanKind, attributes, links) {
|
|
218
|
+
this.updateFlagValue();
|
|
219
|
+
return {
|
|
220
|
+
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
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
updateFlagValue() {
|
|
224
|
+
const variant = this._unleash.getVariant(this._flagName);
|
|
225
|
+
if (variant.payload != null) {
|
|
226
|
+
if (variant.payload.type === "number") {
|
|
227
|
+
this.setRatio(parseFloat(variant.payload.value));
|
|
228
|
+
} else {
|
|
229
|
+
this.setRatio(0);
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
this.setRatio(0);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
setRatio(ratio) {
|
|
236
|
+
this._ratio = this._normalize(ratio);
|
|
237
|
+
this._upperBound = Math.floor(this._ratio * 4294967295);
|
|
238
|
+
}
|
|
239
|
+
toString() {
|
|
240
|
+
return _UnleashSampler.name;
|
|
241
|
+
}
|
|
242
|
+
_normalize(ratio) {
|
|
243
|
+
if (typeof ratio !== "number" || isNaN(ratio)) return 0;
|
|
244
|
+
return ratio >= 1 ? 1 : ratio <= 0 ? 0 : ratio;
|
|
245
|
+
}
|
|
246
|
+
_accumulate(traceId) {
|
|
247
|
+
let accumulation = 0;
|
|
248
|
+
for (let i = 0; i < traceId.length / 8; i++) {
|
|
249
|
+
const pos = i * 8;
|
|
250
|
+
const part = parseInt(traceId.slice(pos, pos + 8), 16);
|
|
251
|
+
accumulation = (accumulation ^ part) >>> 0;
|
|
252
|
+
}
|
|
253
|
+
return accumulation;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var SentryParentSampler = class _SentryParentSampler {
|
|
257
|
+
constructor(config) {
|
|
258
|
+
this._root = config.root;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Checks whether span needs to be created and tracked.
|
|
262
|
+
*
|
|
263
|
+
* @param context Parent Context which may contain a span.
|
|
264
|
+
* @param traceId of the span to be created. It can be different from the
|
|
265
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
266
|
+
* span to be created starts a new trace.
|
|
267
|
+
* @param spanName of the span to be created.
|
|
268
|
+
* @param spanKind of the span to be created.
|
|
269
|
+
* @param attributes Initial set of SpanAttributes for the Span being constructed.
|
|
270
|
+
* @param links Collection of links that will be associated with the Span to
|
|
271
|
+
* be created. Typically useful for batch operations.
|
|
272
|
+
* @returns a {@link SamplingResult}.
|
|
273
|
+
*/
|
|
274
|
+
shouldSample(context, traceId, spanName, spanKind, attributes, links) {
|
|
275
|
+
const decision = this._root.shouldSample(
|
|
276
|
+
context,
|
|
277
|
+
traceId,
|
|
278
|
+
spanName,
|
|
279
|
+
spanKind,
|
|
280
|
+
attributes,
|
|
281
|
+
links
|
|
282
|
+
);
|
|
283
|
+
return (0, import_opentelemetry.wrapSamplingDecision)({
|
|
284
|
+
decision: decision.decision,
|
|
285
|
+
context,
|
|
286
|
+
spanAttributes: attributes
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
toString() {
|
|
290
|
+
return _SentryParentSampler.name;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
181
293
|
// Annotate the CommonJS export names for ESM import in node:
|
|
182
294
|
0 && (module.exports = {
|
|
183
295
|
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,22 @@ async function nodeSDKBuilder(config) {
|
|
|
122
131
|
);
|
|
123
132
|
});
|
|
124
133
|
const sdk = new NodeSDK({
|
|
125
|
-
textMapPropagator: new
|
|
134
|
+
textMapPropagator: new CompositePropagator({
|
|
135
|
+
// The Propogators are run in the order they are added, and since we want the AWSXRAY to win,
|
|
136
|
+
// it must come last because it writes the parent context "sampled" data from the trace into the contexts
|
|
137
|
+
// We Keep Sentry in here, because it adds data that Sentry needs, we just don't want it to control the sample value.
|
|
138
|
+
propagators: [new SentryPropagator(), new AWSXRayPropagator()]
|
|
139
|
+
}),
|
|
126
140
|
instrumentations,
|
|
127
|
-
sampler:
|
|
141
|
+
sampler: new SentryParentSampler({
|
|
142
|
+
root: new ParentBasedSampler({
|
|
143
|
+
root: new UnleashSampler({
|
|
144
|
+
unleash: config.unleash,
|
|
145
|
+
flagName: config.flagName
|
|
146
|
+
// will never be null cause of defaults
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
}),
|
|
128
150
|
contextManager: new Sentry.SentryContextManager(),
|
|
129
151
|
resource: _resource,
|
|
130
152
|
idGenerator: new AWSXRayIdGenerator(),
|
|
@@ -152,6 +174,102 @@ async function nodeSDKBuilder(config) {
|
|
|
152
174
|
).finally(() => process.exit(0));
|
|
153
175
|
});
|
|
154
176
|
}
|
|
177
|
+
var UnleashSampler = class _UnleashSampler {
|
|
178
|
+
constructor(config) {
|
|
179
|
+
this._flagName = config.flagName;
|
|
180
|
+
this._unleash = config.unleash;
|
|
181
|
+
this.setRatio(0);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Checks whether span needs to be created and tracked.
|
|
185
|
+
*
|
|
186
|
+
* @param context Parent Context which may contain a span.
|
|
187
|
+
* @param traceId of the span to be created. It can be different from the
|
|
188
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
189
|
+
* span to be created starts a new trace.
|
|
190
|
+
* @param spanName of the span to be created.
|
|
191
|
+
* @param spanKind of the span to be created.
|
|
192
|
+
* @param attributes Initial set of SpanAttributes for the Span being constructed.
|
|
193
|
+
* @param links Collection of links that will be associated with the Span to
|
|
194
|
+
* be created. Typically useful for batch operations.
|
|
195
|
+
* @returns a {@link SamplingResult}.
|
|
196
|
+
*/
|
|
197
|
+
shouldSample(context, traceId, spanName, spanKind, attributes, links) {
|
|
198
|
+
this.updateFlagValue();
|
|
199
|
+
return {
|
|
200
|
+
decision: isValidTraceId(traceId) && this._accumulate(traceId) < this._upperBound ? SamplingDecision.RECORD_AND_SAMPLED : SamplingDecision.NOT_RECORD
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
updateFlagValue() {
|
|
204
|
+
const variant = this._unleash.getVariant(this._flagName);
|
|
205
|
+
if (variant.payload != null) {
|
|
206
|
+
if (variant.payload.type === "number") {
|
|
207
|
+
this.setRatio(parseFloat(variant.payload.value));
|
|
208
|
+
} else {
|
|
209
|
+
this.setRatio(0);
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
this.setRatio(0);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
setRatio(ratio) {
|
|
216
|
+
this._ratio = this._normalize(ratio);
|
|
217
|
+
this._upperBound = Math.floor(this._ratio * 4294967295);
|
|
218
|
+
}
|
|
219
|
+
toString() {
|
|
220
|
+
return _UnleashSampler.name;
|
|
221
|
+
}
|
|
222
|
+
_normalize(ratio) {
|
|
223
|
+
if (typeof ratio !== "number" || isNaN(ratio)) return 0;
|
|
224
|
+
return ratio >= 1 ? 1 : ratio <= 0 ? 0 : ratio;
|
|
225
|
+
}
|
|
226
|
+
_accumulate(traceId) {
|
|
227
|
+
let accumulation = 0;
|
|
228
|
+
for (let i = 0; i < traceId.length / 8; i++) {
|
|
229
|
+
const pos = i * 8;
|
|
230
|
+
const part = parseInt(traceId.slice(pos, pos + 8), 16);
|
|
231
|
+
accumulation = (accumulation ^ part) >>> 0;
|
|
232
|
+
}
|
|
233
|
+
return accumulation;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var SentryParentSampler = class _SentryParentSampler {
|
|
237
|
+
constructor(config) {
|
|
238
|
+
this._root = config.root;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Checks whether span needs to be created and tracked.
|
|
242
|
+
*
|
|
243
|
+
* @param context Parent Context which may contain a span.
|
|
244
|
+
* @param traceId of the span to be created. It can be different from the
|
|
245
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
246
|
+
* span to be created starts a new trace.
|
|
247
|
+
* @param spanName of the span to be created.
|
|
248
|
+
* @param spanKind of the span to be created.
|
|
249
|
+
* @param attributes Initial set of SpanAttributes for the Span being constructed.
|
|
250
|
+
* @param links Collection of links that will be associated with the Span to
|
|
251
|
+
* be created. Typically useful for batch operations.
|
|
252
|
+
* @returns a {@link SamplingResult}.
|
|
253
|
+
*/
|
|
254
|
+
shouldSample(context, traceId, spanName, spanKind, attributes, links) {
|
|
255
|
+
const decision = this._root.shouldSample(
|
|
256
|
+
context,
|
|
257
|
+
traceId,
|
|
258
|
+
spanName,
|
|
259
|
+
spanKind,
|
|
260
|
+
attributes,
|
|
261
|
+
links
|
|
262
|
+
);
|
|
263
|
+
return wrapSamplingDecision({
|
|
264
|
+
decision: decision.decision,
|
|
265
|
+
context,
|
|
266
|
+
spanAttributes: attributes
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
toString() {
|
|
270
|
+
return _SentryParentSampler.name;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
155
273
|
export {
|
|
156
274
|
AdditionalInstrumentation,
|
|
157
275
|
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.8",
|
|
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",
|