@palmetto/pubsub 2.2.0 → 2.2.1

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.
@@ -1,9 +1,60 @@
1
1
  interface Span {
2
+ /**
3
+ * Sets the end timestamp and finalizes Span state.
4
+ *
5
+ * With the exception of calls to Span.context() (which are always allowed),
6
+ * finish() must be the last call made to any span instance, and to do
7
+ * otherwise leads to undefined behavior.
8
+ */
2
9
  finish(): void;
10
+ /**
11
+ * Adds a single tag to the span. See `addTags()` for details.
12
+ *
13
+ * @param {string} key
14
+ * @param {any} value
15
+ */
3
16
  setTag(key: string, value: unknown): this;
4
17
  }
18
+ interface SpanOptions {
19
+ /**
20
+ * a parent SpanContext (or Span, for convenience) that the newly-started
21
+ * span will be the child of (per REFERENCE_CHILD_OF). If specified,
22
+ * `references` must be unspecified.
23
+ */
24
+ childOf: Span | null;
25
+ /**
26
+ * set of key-value pairs which will be set as tags on the newly created
27
+ * Span. Ownership of the object is passed to the created span for
28
+ * efficiency reasons (the caller should not modify this object after
29
+ * calling startSpan).
30
+ */
31
+ tags: {
32
+ [key: string]: unknown;
33
+ };
34
+ }
35
+ /**
36
+ * The Datadog Scope Manager. This is used for context propagation.
37
+ */
38
+ interface Scope {
39
+ /**
40
+ * Get the current active span or null if there is none.
41
+ *
42
+ * @returns {Span} The active span.
43
+ */
44
+ active(): Span | null;
45
+ }
5
46
  interface Tracer {
6
- startSpan(name: string): Span;
47
+ /**
48
+ * Starts and returns a new Span representing a logical unit of work.
49
+ * @param {string} name The name of the operation.
50
+ * @param {SpanOptions} [options] Options for the newly created span.
51
+ * @returns {Span} A new Span object.
52
+ */
53
+ startSpan(name: string, options: SpanOptions): Span;
54
+ /**
55
+ * Returns a reference to the current scope.
56
+ */
57
+ scope(): Scope;
7
58
  }
8
59
  export declare function getTracer(): Tracer;
9
60
  export declare function registerDdTrace(tracer: Tracer): void;
@@ -10,12 +10,21 @@ class NoOpSpan {
10
10
  return this;
11
11
  }
12
12
  }
13
+ class NoOpScope {
14
+ active() {
15
+ return null;
16
+ }
17
+ }
13
18
  class NoOpTracer {
14
19
  constructor() {
15
- this.span = new NoOpSpan();
20
+ this.noOpSpan = new NoOpSpan();
21
+ this.noOpScope = new NoOpScope();
22
+ }
23
+ startSpan(_name, _options) {
24
+ return this.noOpSpan;
16
25
  }
17
- startSpan(_name) {
18
- return this.span;
26
+ scope() {
27
+ return this.noOpScope;
19
28
  }
20
29
  }
21
30
  let tracerInstance = new NoOpTracer();
package/dist/publisher.js CHANGED
@@ -54,10 +54,14 @@ class Publisher {
54
54
  }
55
55
  publish(config, message) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
- const span = (0, dd_trace_wrapper_js_1.getTracer)()
58
- .startSpan("Publisher.publish")
59
- .setTag("pubsub.transport", config.transport)
60
- .setTag("pubsub.name", config.name);
57
+ const tracer = (0, dd_trace_wrapper_js_1.getTracer)();
58
+ const span = tracer.startSpan("pubsub.publish", {
59
+ childOf: tracer.scope().active(),
60
+ tags: {
61
+ "pubsub.transport": config.transport,
62
+ "pubsub.name": config.name,
63
+ },
64
+ });
61
65
  try {
62
66
  const provider = this.getProvider(config);
63
67
  const { schema, schemaId } = this.assertSchema(config);
@@ -57,10 +57,14 @@ class Subscriber {
57
57
  throw new errors_js_1.MissingPubSubProviderError(`No provider configured for ${config.transport}`);
58
58
  }
59
59
  const transform = (jsonStr, context) => __awaiter(this, void 0, void 0, function* () {
60
- const span = (0, dd_trace_wrapper_js_1.getTracer)()
61
- .startSpan("Subscriber.handleMessage")
62
- .setTag("pubsub.transport", config.transport)
63
- .setTag("pubsub.name", config.name);
60
+ const tracer = (0, dd_trace_wrapper_js_1.getTracer)();
61
+ const span = tracer.startSpan("pubsub.handleMessage", {
62
+ childOf: tracer.scope().active(),
63
+ tags: {
64
+ "pubsub.transport": config.transport,
65
+ "pubsub.name": config.name,
66
+ },
67
+ });
64
68
  const start = (0, message_logger_js_1.startTiming)();
65
69
  const jsonObject = JSON.parse(jsonStr);
66
70
  const r = schema.safeDecode(jsonObject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palmetto/pubsub",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "main": "./dist/main.js",
5
5
  "scripts": {
6
6
  "lint": "yarn run -T eslint --fix ./src",