@orpc/opentelemetry 2.0.0-beta.46 → 2.0.0-beta.48

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/README.md CHANGED
@@ -156,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
156
156
  <td align="center"><a href="https://github.com/christ12938?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
157
157
  <td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
158
158
  <td align="center"><a href="https://github.com/itigoore01?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="167" alt="shota"/><br />shota</a></td>
159
+ <td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&amp;v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
159
160
  <td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&amp;v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
160
- <td align="center"><a href="https://github.com/hoangbn?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&amp;v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
161
161
  </tr>
162
162
  <tr>
163
+ <td align="center"><a href="https://github.com/hoangbn?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&amp;v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
163
164
  <td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
164
165
  <td align="center"><a href="https://automatio.ai/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&amp;v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
165
166
  </tr>
@@ -190,10 +191,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
190
191
  <td align="center"><a href="https://kellychan.im/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
191
192
  <td align="center"><a href="https://guyariely.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&amp;v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
192
193
  <td align="center"><a href="https://paulsenon.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&amp;v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
193
- <td align="center"><a href="https://nakasyou.how/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Shotaro Nakamura"><img src="https://avatars.githubusercontent.com/u/79000684?u=f644df3f29f0e8677a90967115774564f1d9d6ab&amp;v=4" width="139" alt="Shotaro Nakamura"/><br />Shotaro Nakamura</a></td>
194
+ <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
194
195
  </tr>
195
196
  <tr>
196
- <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
197
197
  <td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&amp;v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
198
198
  </tr>
199
199
  </table>
@@ -206,7 +206,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
206
206
 
207
207
  <table>
208
208
  <tr>
209
- <td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude for Open Source</a></td>
209
+ <td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
210
+ <td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&amp;v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
211
+ <td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&amp;v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
210
212
  </tr>
211
213
  </table>
212
214
 
package/dist/index.d.mts CHANGED
@@ -1,27 +1 @@
1
- import { InstrumentationBase, InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
2
-
3
- interface ORPCInstrumentationConfig extends InstrumentationConfig {
4
- /**
5
- * Whether to enable automatic OpenTelemetry context/span propagation.
6
- *
7
- * Disable this if propagation is handled elsewhere or managed manually.
8
- *
9
- * @default true
10
- */
11
- propagationEnabled?: boolean | undefined;
12
- }
13
- /**
14
- * OpenTelemetry instrumentation for oRPC. Automatically instruments both
15
- * client and server for distributed tracing.
16
- *
17
- * @see {@link https://orpc.dev/docs/integrations/opentelemetry | OpenTelemetry Integration}
18
- */
19
- declare class ORPCInstrumentation extends InstrumentationBase<ORPCInstrumentationConfig> {
20
- constructor(config?: ORPCInstrumentationConfig);
21
- protected init(): InstrumentationModuleDefinition | InstrumentationModuleDefinition[] | void;
22
- enable(): void;
23
- disable(): void;
24
- }
25
-
26
- export { ORPCInstrumentation };
27
- export type { ORPCInstrumentationConfig };
1
+ export * from "./instrumentation.mjs";
package/dist/index.mjs CHANGED
@@ -1,100 +1 @@
1
- import { SpanStatusCode, propagation, context, trace } from '@opentelemetry/api';
2
- import { InstrumentationBase } from '@opentelemetry/instrumentation';
3
- import { setTracer } from '@orpc/shared';
4
-
5
- const name = "@orpc/opentelemetry";
6
- const version = "2.0.0-beta.46";
7
- const pkg = {
8
- name: name,
9
- version: version};
10
-
11
- class OpenTelemetrySpan {
12
- constructor(span) {
13
- this.span = span;
14
- }
15
- setAttribute(key, value) {
16
- this.span.setAttribute(key, value);
17
- }
18
- updateName(name) {
19
- this.span.updateName(name);
20
- }
21
- addEvent(name) {
22
- this.span.addEvent(name);
23
- }
24
- recordException(level, exception) {
25
- this.span.recordException(exception);
26
- if (level === "error") {
27
- this.span.setStatus({
28
- code: SpanStatusCode.ERROR,
29
- message: exception.message
30
- });
31
- }
32
- }
33
- end() {
34
- this.span.end();
35
- }
36
- }
37
- class OpenTelemetryTracer {
38
- tracer;
39
- trace;
40
- context;
41
- inject;
42
- extract;
43
- constructor(options) {
44
- this.tracer = options.tracer;
45
- this.trace = options.trace;
46
- this.context = options.context;
47
- const propagation = options.propagation;
48
- if (propagation !== void 0) {
49
- this.inject = (span, headers) => {
50
- propagation.inject(this.contextOf(span), headers);
51
- };
52
- this.extract = (headers) => {
53
- const span = this.trace.getSpan(propagation.extract(this.context.active(), headers));
54
- return span === void 0 ? void 0 : new OpenTelemetrySpan(span);
55
- };
56
- }
57
- }
58
- startSpan(name, parent) {
59
- const span = parent === void 0 ? this.tracer().startSpan(name) : this.tracer().startSpan(name, void 0, this.contextOf(parent));
60
- return new OpenTelemetrySpan(span);
61
- }
62
- startActiveSpan(name, parent, fn) {
63
- const callback = (span) => fn(new OpenTelemetrySpan(span));
64
- if (parent === void 0) {
65
- return this.tracer().startActiveSpan(name, callback);
66
- }
67
- return this.tracer().startActiveSpan(name, {}, this.contextOf(parent), callback);
68
- }
69
- getActiveSpan() {
70
- const span = this.trace.getActiveSpan();
71
- return span === void 0 ? void 0 : new OpenTelemetrySpan(span);
72
- }
73
- withActiveSpan(span, fn) {
74
- return this.context.with(this.contextOf(span), fn);
75
- }
76
- contextOf(parent) {
77
- return this.trace.setSpan(this.context.active(), parent.span);
78
- }
79
- }
80
-
81
- class ORPCInstrumentation extends InstrumentationBase {
82
- constructor(config = {}) {
83
- super(pkg.name, pkg.version, config);
84
- }
85
- init() {
86
- }
87
- enable() {
88
- setTracer(new OpenTelemetryTracer({
89
- tracer: () => this.tracer,
90
- trace,
91
- context,
92
- propagation: this._config.propagationEnabled ?? true ? propagation : void 0
93
- }));
94
- }
95
- disable() {
96
- setTracer(void 0);
97
- }
98
- }
99
-
100
- export { ORPCInstrumentation };
1
+ export * from "./instrumentation.mjs";
@@ -0,0 +1,24 @@
1
+ import type { InstrumentationConfig, InstrumentationModuleDefinition } from "@opentelemetry/instrumentation";
2
+ import { InstrumentationBase } from "@opentelemetry/instrumentation";
3
+ export interface ORPCInstrumentationConfig extends InstrumentationConfig {
4
+ /**
5
+ * Whether to enable automatic OpenTelemetry context/span propagation.
6
+ *
7
+ * Disable this if propagation is handled elsewhere or managed manually.
8
+ *
9
+ * @default true
10
+ */
11
+ propagationEnabled?: boolean | undefined;
12
+ }
13
+ /**
14
+ * OpenTelemetry instrumentation for oRPC. Automatically instruments both
15
+ * client and server for distributed tracing.
16
+ *
17
+ * @see {@link https://orpc.dev/docs/integrations/opentelemetry | OpenTelemetry Integration}
18
+ */
19
+ export declare class ORPCInstrumentation extends InstrumentationBase<ORPCInstrumentationConfig> {
20
+ constructor(config?: ORPCInstrumentationConfig);
21
+ protected override init(): InstrumentationModuleDefinition | InstrumentationModuleDefinition[] | void;
22
+ override enable(): void;
23
+ override disable(): void;
24
+ }
@@ -0,0 +1,23 @@
1
+ import { context, propagation, trace } from "@opentelemetry/api";
2
+ import { InstrumentationBase } from "@opentelemetry/instrumentation";
3
+ import { setTracer } from "@orpc/shared";
4
+ import pkg from "../package.json" with { type: "json" };
5
+ import { OpenTelemetryTracer } from "./tracer.mjs";
6
+
7
+ export class ORPCInstrumentation extends InstrumentationBase {
8
+ constructor(config = {}) {
9
+ super(pkg.name, pkg.version, config);
10
+ }
11
+ init() {}
12
+ enable() {
13
+ setTracer(new OpenTelemetryTracer({
14
+ tracer: () => this.tracer,
15
+ trace,
16
+ context,
17
+ propagation: this._config.propagationEnabled ?? true ? propagation : undefined
18
+ }));
19
+ }
20
+ disable() {
21
+ setTracer(undefined);
22
+ }
23
+ }
@@ -0,0 +1,36 @@
1
+ import type { ContextAPI, Tracer as OpenTelemetryApiTracer, PropagationAPI, Span, TraceAPI } from "@opentelemetry/api";
2
+ import type { Promisable, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingSpan } from "@orpc/shared";
3
+ export declare class OpenTelemetrySpan implements TracingSpan {
4
+ readonly span: Span;
5
+ constructor(span: Span);
6
+ setAttribute(key: string, value: TracingAttributeValue): void;
7
+ updateName(name: string): void;
8
+ addEvent(name: string): void;
9
+ recordException(level: TracingExceptionLevel, exception: TracingException): void;
10
+ end(): void;
11
+ }
12
+ export interface OpenTelemetryTracerOptions {
13
+ /**
14
+ * Called for every span, so a tracer provider set after construction is picked up.
15
+ */
16
+ tracer: () => OpenTelemetryApiTracer;
17
+ trace: TraceAPI;
18
+ context: ContextAPI;
19
+ /**
20
+ * propagation is optional, can reduce bundle size in some cases.
21
+ */
22
+ propagation?: PropagationAPI | undefined;
23
+ }
24
+ export declare class OpenTelemetryTracer implements Tracer {
25
+ private readonly tracer;
26
+ private readonly trace;
27
+ private readonly context;
28
+ readonly inject: Tracer["inject"];
29
+ readonly extract: Tracer["extract"];
30
+ constructor(options: OpenTelemetryTracerOptions);
31
+ startSpan(name: string, parent?: TracingSpan): TracingSpan;
32
+ startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
33
+ getActiveSpan(): TracingSpan | undefined;
34
+ withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
35
+ private contextOf;
36
+ }
@@ -0,0 +1,71 @@
1
+ import { SpanStatusCode } from "@opentelemetry/api";
2
+ export class OpenTelemetrySpan {
3
+ span;
4
+ constructor(span) {
5
+ this.span = span;
6
+ }
7
+ setAttribute(key, value) {
8
+ this.span.setAttribute(key, value);
9
+ }
10
+ updateName(name) {
11
+ this.span.updateName(name);
12
+ }
13
+ addEvent(name) {
14
+ this.span.addEvent(name);
15
+ }
16
+ recordException(level, exception) {
17
+ this.span.recordException(exception);
18
+ if (level === "error") {
19
+ this.span.setStatus({
20
+ code: SpanStatusCode.ERROR,
21
+ message: exception.message
22
+ });
23
+ }
24
+ }
25
+ end() {
26
+ this.span.end();
27
+ }
28
+ }
29
+ export class OpenTelemetryTracer {
30
+ tracer;
31
+ trace;
32
+ context;
33
+ inject;
34
+ extract;
35
+ constructor(options) {
36
+ this.tracer = options.tracer;
37
+ this.trace = options.trace;
38
+ this.context = options.context;
39
+ const propagation = options.propagation;
40
+ if (propagation !== undefined) {
41
+ this.inject = (span, headers) => {
42
+ propagation.inject(this.contextOf(span), headers);
43
+ };
44
+ this.extract = (headers) => {
45
+ const span = this.trace.getSpan(propagation.extract(this.context.active(), headers));
46
+ return span === undefined ? undefined : new OpenTelemetrySpan(span);
47
+ };
48
+ }
49
+ }
50
+ startSpan(name, parent) {
51
+ const span = parent === undefined ? this.tracer().startSpan(name) : this.tracer().startSpan(name, undefined, this.contextOf(parent));
52
+ return new OpenTelemetrySpan(span);
53
+ }
54
+ startActiveSpan(name, parent, fn) {
55
+ const callback = (span) => fn(new OpenTelemetrySpan(span));
56
+ if (parent === undefined) {
57
+ return this.tracer().startActiveSpan(name, callback);
58
+ }
59
+ return this.tracer().startActiveSpan(name, {}, this.contextOf(parent), callback);
60
+ }
61
+ getActiveSpan() {
62
+ const span = this.trace.getActiveSpan();
63
+ return span === undefined ? undefined : new OpenTelemetrySpan(span);
64
+ }
65
+ withActiveSpan(span, fn) {
66
+ return this.context.with(this.contextOf(span), fn);
67
+ }
68
+ contextOf(parent) {
69
+ return this.trace.setSpan(this.context.active(), parent.span);
70
+ }
71
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/opentelemetry",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.46",
4
+ "version": "2.0.0-beta.48",
5
5
  "description": "OpenTelemetry integration for oRPC: distributed tracing for typesafe APIs",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -39,11 +39,11 @@
39
39
  "@opentelemetry/instrumentation": ">=0.203.0"
40
40
  },
41
41
  "dependencies": {
42
- "@orpc/shared": "2.0.0-beta.46"
42
+ "@orpc/shared": "2.0.0-beta.48"
43
43
  },
44
44
  "devDependencies": {
45
- "@opentelemetry/api": "^1.9.1",
46
- "@opentelemetry/instrumentation": "^0.223.0",
45
+ "@opentelemetry/api": "^1.10.0",
46
+ "@opentelemetry/instrumentation": "^0.300.0",
47
47
  "@opentelemetry/sdk-trace-node": "^2.12.0"
48
48
  },
49
49
  "scripts": {
package/dist/index.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { InstrumentationBase, InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
2
-
3
- interface ORPCInstrumentationConfig extends InstrumentationConfig {
4
- /**
5
- * Whether to enable automatic OpenTelemetry context/span propagation.
6
- *
7
- * Disable this if propagation is handled elsewhere or managed manually.
8
- *
9
- * @default true
10
- */
11
- propagationEnabled?: boolean | undefined;
12
- }
13
- /**
14
- * OpenTelemetry instrumentation for oRPC. Automatically instruments both
15
- * client and server for distributed tracing.
16
- *
17
- * @see {@link https://orpc.dev/docs/integrations/opentelemetry | OpenTelemetry Integration}
18
- */
19
- declare class ORPCInstrumentation extends InstrumentationBase<ORPCInstrumentationConfig> {
20
- constructor(config?: ORPCInstrumentationConfig);
21
- protected init(): InstrumentationModuleDefinition | InstrumentationModuleDefinition[] | void;
22
- enable(): void;
23
- disable(): void;
24
- }
25
-
26
- export { ORPCInstrumentation };
27
- export type { ORPCInstrumentationConfig };