1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.ParentBasedSampler = void 0;
|
19 | const api_1 = require("@opentelemetry/api");
|
20 | const global_error_handler_1 = require("../../common/global-error-handler");
|
21 | const AlwaysOffSampler_1 = require("./AlwaysOffSampler");
|
22 | const AlwaysOnSampler_1 = require("./AlwaysOnSampler");
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | class ParentBasedSampler {
|
29 | constructor(config) {
|
30 | var _a, _b, _c, _d;
|
31 | this._root = config.root;
|
32 | if (!this._root) {
|
33 | (0, global_error_handler_1.globalErrorHandler)(new Error('ParentBasedSampler must have a root sampler configured'));
|
34 | this._root = new AlwaysOnSampler_1.AlwaysOnSampler();
|
35 | }
|
36 | this._remoteParentSampled =
|
37 | (_a = config.remoteParentSampled) !== null && _a !== void 0 ? _a : new AlwaysOnSampler_1.AlwaysOnSampler();
|
38 | this._remoteParentNotSampled =
|
39 | (_b = config.remoteParentNotSampled) !== null && _b !== void 0 ? _b : new AlwaysOffSampler_1.AlwaysOffSampler();
|
40 | this._localParentSampled =
|
41 | (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1.AlwaysOnSampler();
|
42 | this._localParentNotSampled =
|
43 | (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1.AlwaysOffSampler();
|
44 | }
|
45 | shouldSample(context, traceId, spanName, spanKind, attributes, links) {
|
46 | const parentContext = api_1.trace.getSpanContext(context);
|
47 | if (!parentContext || !(0, api_1.isSpanContextValid)(parentContext)) {
|
48 | return this._root.shouldSample(context, traceId, spanName, spanKind, attributes, links);
|
49 | }
|
50 | if (parentContext.isRemote) {
|
51 | if (parentContext.traceFlags & api_1.TraceFlags.SAMPLED) {
|
52 | return this._remoteParentSampled.shouldSample(context, traceId, spanName, spanKind, attributes, links);
|
53 | }
|
54 | return this._remoteParentNotSampled.shouldSample(context, traceId, spanName, spanKind, attributes, links);
|
55 | }
|
56 | if (parentContext.traceFlags & api_1.TraceFlags.SAMPLED) {
|
57 | return this._localParentSampled.shouldSample(context, traceId, spanName, spanKind, attributes, links);
|
58 | }
|
59 | return this._localParentNotSampled.shouldSample(context, traceId, spanName, spanKind, attributes, links);
|
60 | }
|
61 | toString() {
|
62 | return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
|
63 | }
|
64 | }
|
65 | exports.ParentBasedSampler = ParentBasedSampler;
|
66 |
|
\ | No newline at end of file |