@orpc/opentelemetry 2.0.0-beta.34 → 2.0.0-beta.35

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.
Files changed (3) hide show
  1. package/README.md +15 -14
  2. package/dist/index.mjs +76 -6
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -55,20 +55,20 @@ You can read the documentation [here](https://orpc.dev).
55
55
 
56
56
  **Framework & ecosystem integrations**
57
57
 
58
- | Package | Purpose | Docs |
59
- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
60
- | [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
61
- | [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
62
- | [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
63
- | [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
64
- | [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
65
- | [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
66
- | [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
67
- | [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
68
- | [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
69
- | [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
70
- | [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
71
- | [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
58
+ | Package | Purpose | Docs |
59
+ | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
60
+ | [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
61
+ | [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
62
+ | [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
63
+ | [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
64
+ | [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
65
+ | [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
66
+ | [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
67
+ | [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
68
+ | [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
69
+ | [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
70
+ | [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare Workers](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
71
+ | [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
72
72
 
73
73
  **Observability**
74
74
 
@@ -127,6 +127,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
127
127
  <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="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
128
128
  <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="139" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
129
129
  <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="139" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
130
+ <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="139" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
130
131
  </tr>
131
132
  </table>
132
133
 
package/dist/index.mjs CHANGED
@@ -1,13 +1,83 @@
1
- import { propagation, context, trace } from '@opentelemetry/api';
1
+ import { SpanStatusCode, propagation, context, trace } from '@opentelemetry/api';
2
2
  import { InstrumentationBase } from '@opentelemetry/instrumentation';
3
- import { setOpenTelemetryConfig } from '@orpc/shared';
3
+ import { setTracer } from '@orpc/shared';
4
4
 
5
5
  const name = "@orpc/opentelemetry";
6
- const version = "2.0.0-beta.34";
6
+ const version = "2.0.0-beta.35";
7
7
  const pkg = {
8
8
  name: name,
9
9
  version: version};
10
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
+
11
81
  class ORPCInstrumentation extends InstrumentationBase {
12
82
  constructor(config = {}) {
13
83
  super(pkg.name, pkg.version, config);
@@ -15,15 +85,15 @@ class ORPCInstrumentation extends InstrumentationBase {
15
85
  init() {
16
86
  }
17
87
  enable() {
18
- setOpenTelemetryConfig({
88
+ setTracer(new OpenTelemetryTracer({
19
89
  tracer: trace.getTracer(pkg.name, pkg.version),
20
90
  trace,
21
91
  context,
22
92
  propagation: this._config.propagationEnabled ?? true ? propagation : void 0
23
- });
93
+ }));
24
94
  }
25
95
  disable() {
26
- setOpenTelemetryConfig(void 0);
96
+ setTracer(void 0);
27
97
  }
28
98
  }
29
99
 
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.34",
4
+ "version": "2.0.0-beta.35",
5
5
  "description": "OpenTelemetry integration for oRPC: distributed tracing for typesafe APIs",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -39,11 +39,12 @@
39
39
  "@opentelemetry/instrumentation": ">=0.203.0"
40
40
  },
41
41
  "dependencies": {
42
- "@orpc/shared": "2.0.0-beta.34"
42
+ "@orpc/shared": "2.0.0-beta.35"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@opentelemetry/api": "^1.9.1",
46
- "@opentelemetry/instrumentation": "^0.221.0"
46
+ "@opentelemetry/instrumentation": "^0.221.0",
47
+ "@opentelemetry/sdk-trace-node": "^2.10.0"
47
48
  },
48
49
  "scripts": {
49
50
  "type:check": "tsc -b"