@orpc/opentelemetry 2.0.0-beta.47 → 2.0.0-beta.49
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 +6 -7
- package/dist/index.d.ts +2 -27
- package/dist/index.js +1 -0
- package/dist/instrumentation.d.ts +27 -0
- package/dist/instrumentation.js +28 -0
- package/dist/tracer.d.ts +68 -0
- package/dist/tracer.js +95 -0
- package/package.json +27 -29
- package/dist/index.d.mts +0 -27
- package/dist/index.mjs +0 -100
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
6
6
|
</a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/@orpc/opentelemetry">
|
|
8
|
-
<img alt="
|
|
8
|
+
<img alt="monthly downloads" src="https://img.shields.io/npm/dm/%40orpc%2Fopentelemetry?logo=npm" />
|
|
9
9
|
</a>
|
|
10
10
|
<a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
|
|
11
11
|
<img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
|
|
@@ -41,10 +41,11 @@ export const router = {
|
|
|
41
41
|
Then call them from a client that knows every input and output, without generating anything:
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
|
-
import type { RouterClient } from '@orpc/server'
|
|
45
|
-
import type { router } from './router'
|
|
46
44
|
import { createORPCClient } from '@orpc/client'
|
|
47
45
|
import { RPCLink } from '@orpc/client/fetch'
|
|
46
|
+
import type { RouterClient } from '@orpc/server'
|
|
47
|
+
|
|
48
|
+
import type { router } from './router'
|
|
48
49
|
|
|
49
50
|
const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
|
|
50
51
|
const client: RouterClient<typeof router> = createORPCClient(link)
|
|
@@ -191,15 +192,14 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
191
192
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
192
193
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
193
194
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
194
|
-
<td align="center"><a href="https://
|
|
195
|
+
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
195
196
|
</tr>
|
|
196
197
|
<tr>
|
|
197
|
-
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
198
198
|
<td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
199
199
|
</tr>
|
|
200
200
|
</table>
|
|
201
201
|
|
|
202
|
-
With thanks to [
|
|
202
|
+
With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
203
203
|
|
|
204
204
|
## Open Source Programs
|
|
205
205
|
|
|
@@ -209,7 +209,6 @@ With thanks to [39 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
209
209
|
<tr>
|
|
210
210
|
<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>
|
|
211
211
|
<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&v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
|
|
212
|
-
<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&v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
|
|
213
212
|
</tr>
|
|
214
213
|
</table>
|
|
215
214
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
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.ts';
|
|
2
|
+
export type { OpenTelemetryPropagationOptions } from './tracer.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instrumentation.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
2
|
+
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
3
|
+
import type { OpenTelemetryPropagationOptions } from './tracer.ts';
|
|
4
|
+
export interface ORPCInstrumentationConfig extends InstrumentationConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Automatic OpenTelemetry context/span propagation. `false` disables it,
|
|
7
|
+
* {@link OpenTelemetryPropagationOptions} controls each direction separately.
|
|
8
|
+
*
|
|
9
|
+
* Disable this if propagation is handled elsewhere or managed manually.
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
propagation?: boolean | OpenTelemetryPropagationOptions | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* OpenTelemetry instrumentation for oRPC. Automatically instruments both
|
|
17
|
+
* client and server for distributed tracing.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/integrations/opentelemetry | OpenTelemetry Integration}
|
|
20
|
+
*/
|
|
21
|
+
export declare class ORPCInstrumentation extends InstrumentationBase<ORPCInstrumentationConfig> {
|
|
22
|
+
constructor(config?: ORPCInstrumentationConfig);
|
|
23
|
+
protected init(): void;
|
|
24
|
+
enable(): void;
|
|
25
|
+
disable(): void;
|
|
26
|
+
isEnabled(): boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
2
|
+
import { getTracer, setTracer } from '@orpc/shared';
|
|
3
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
4
|
+
import { OpenTelemetryTracer } from './tracer.js';
|
|
5
|
+
/**
|
|
6
|
+
* OpenTelemetry instrumentation for oRPC. Automatically instruments both
|
|
7
|
+
* client and server for distributed tracing.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://orpc.dev/docs/integrations/opentelemetry | OpenTelemetry Integration}
|
|
10
|
+
*/
|
|
11
|
+
export class ORPCInstrumentation extends InstrumentationBase {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
super(pkg.name, pkg.version, config);
|
|
14
|
+
}
|
|
15
|
+
init() { }
|
|
16
|
+
enable() {
|
|
17
|
+
setTracer(new OpenTelemetryTracer({
|
|
18
|
+
tracer: () => this.tracer,
|
|
19
|
+
propagation: this.getConfig().propagation,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
disable() {
|
|
23
|
+
setTracer(undefined);
|
|
24
|
+
}
|
|
25
|
+
isEnabled() {
|
|
26
|
+
return getTracer() !== undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/tracer.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Context, Tracer as OpenTelemetryApiTracer, Span } from '@opentelemetry/api';
|
|
2
|
+
import type { Promisable, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingSpan } from '@orpc/shared';
|
|
3
|
+
export declare class OpenTelemetrySpan implements TracingSpan {
|
|
4
|
+
/**
|
|
5
|
+
* The context the span was started or extracted in, with the span set as its active span.
|
|
6
|
+
* Children and `withActiveSpan` use it as-is, so baggage and other context values are kept
|
|
7
|
+
* even when the span is used later, e.g. while a streamed response is consumed.
|
|
8
|
+
*
|
|
9
|
+
* An extracted parent with only baggage has no span here, so its children start a new trace.
|
|
10
|
+
*/
|
|
11
|
+
readonly context: Context;
|
|
12
|
+
readonly span: Span;
|
|
13
|
+
constructor(
|
|
14
|
+
/**
|
|
15
|
+
* The context the span was started or extracted in, with the span set as its active span.
|
|
16
|
+
* Children and `withActiveSpan` use it as-is, so baggage and other context values are kept
|
|
17
|
+
* even when the span is used later, e.g. while a streamed response is consumed.
|
|
18
|
+
*
|
|
19
|
+
* An extracted parent with only baggage has no span here, so its children start a new trace.
|
|
20
|
+
*/
|
|
21
|
+
context: Context);
|
|
22
|
+
setAttribute(key: string, value: TracingAttributeValue): void;
|
|
23
|
+
updateName(name: string): void;
|
|
24
|
+
addEvent(name: string): void;
|
|
25
|
+
recordException(level: TracingExceptionLevel, exception: TracingException): void;
|
|
26
|
+
end(): void;
|
|
27
|
+
}
|
|
28
|
+
export interface OpenTelemetryPropagationOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Whether oRPC links write the trace context and baggage of the active span into outgoing request headers.
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
inject?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Whether oRPC handlers read the trace context and baggage from incoming request headers and continue that trace.
|
|
37
|
+
*
|
|
38
|
+
* Disable this when callers are untrusted, e.g. public web clients.
|
|
39
|
+
*
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
extract?: boolean | undefined;
|
|
43
|
+
}
|
|
44
|
+
export interface OpenTelemetryTracerOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Called for every span, so a tracer provider set after construction is picked up.
|
|
47
|
+
*/
|
|
48
|
+
tracer: () => OpenTelemetryApiTracer;
|
|
49
|
+
/**
|
|
50
|
+
* Automatic OpenTelemetry context propagation. `false` disables it,
|
|
51
|
+
* {@link OpenTelemetryPropagationOptions} controls each direction separately.
|
|
52
|
+
*
|
|
53
|
+
* Disable this if propagation is handled elsewhere or managed manually.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
propagation?: boolean | OpenTelemetryPropagationOptions | undefined;
|
|
58
|
+
}
|
|
59
|
+
export declare class OpenTelemetryTracer implements Tracer {
|
|
60
|
+
private readonly tracer;
|
|
61
|
+
readonly inject: Tracer['inject'];
|
|
62
|
+
readonly extract: Tracer['extract'];
|
|
63
|
+
constructor(options: OpenTelemetryTracerOptions);
|
|
64
|
+
startSpan(name: string, parent?: TracingSpan): TracingSpan;
|
|
65
|
+
startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
|
|
66
|
+
getActiveSpan(): TracingSpan | undefined;
|
|
67
|
+
withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
|
|
68
|
+
}
|
package/dist/tracer.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { context, INVALID_SPAN_CONTEXT, propagation, SpanStatusCode, trace, } from '@opentelemetry/api';
|
|
2
|
+
export class OpenTelemetrySpan {
|
|
3
|
+
context;
|
|
4
|
+
span;
|
|
5
|
+
constructor(
|
|
6
|
+
/**
|
|
7
|
+
* The context the span was started or extracted in, with the span set as its active span.
|
|
8
|
+
* Children and `withActiveSpan` use it as-is, so baggage and other context values are kept
|
|
9
|
+
* even when the span is used later, e.g. while a streamed response is consumed.
|
|
10
|
+
*
|
|
11
|
+
* An extracted parent with only baggage has no span here, so its children start a new trace.
|
|
12
|
+
*/
|
|
13
|
+
context) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.span = trace.getSpan(context) ?? trace.wrapSpanContext(INVALID_SPAN_CONTEXT);
|
|
16
|
+
}
|
|
17
|
+
setAttribute(key, value) {
|
|
18
|
+
this.span.setAttribute(key, value);
|
|
19
|
+
}
|
|
20
|
+
updateName(name) {
|
|
21
|
+
this.span.updateName(name);
|
|
22
|
+
}
|
|
23
|
+
addEvent(name) {
|
|
24
|
+
this.span.addEvent(name);
|
|
25
|
+
}
|
|
26
|
+
recordException(level, exception) {
|
|
27
|
+
this.span.recordException(exception);
|
|
28
|
+
if (level === 'error') {
|
|
29
|
+
this.span.setStatus({ code: SpanStatusCode.ERROR, message: exception.message });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
end() {
|
|
33
|
+
this.span.end();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class OpenTelemetryTracer {
|
|
37
|
+
tracer;
|
|
38
|
+
inject;
|
|
39
|
+
extract;
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.tracer = options.tracer;
|
|
42
|
+
const enabled = typeof options.propagation === 'object'
|
|
43
|
+
? options.propagation
|
|
44
|
+
: { inject: options.propagation, extract: options.propagation };
|
|
45
|
+
if (enabled.inject ?? true) {
|
|
46
|
+
this.inject = (span, headers) => {
|
|
47
|
+
propagation.inject(contextOf(span), headers);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (enabled.extract ?? true) {
|
|
51
|
+
this.extract = (headers) => {
|
|
52
|
+
const active = context.active();
|
|
53
|
+
const extracted = withActiveBaggage(propagation.extract(active, headers), active);
|
|
54
|
+
return extracted === active && trace.getSpan(active) === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: new OpenTelemetrySpan(extracted);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
startSpan(name, parent) {
|
|
61
|
+
const parentContext = contextOf(parent);
|
|
62
|
+
const span = this.tracer().startSpan(name, undefined, parentContext);
|
|
63
|
+
return new OpenTelemetrySpan(trace.setSpan(parentContext, span));
|
|
64
|
+
}
|
|
65
|
+
startActiveSpan(name, parent, fn) {
|
|
66
|
+
// Same as the OpenTelemetry SDK's startActiveSpan, but the stored context does not depend on a context manager
|
|
67
|
+
const span = this.startSpan(name, parent);
|
|
68
|
+
return context.with(span.context, fn, undefined, span);
|
|
69
|
+
}
|
|
70
|
+
getActiveSpan() {
|
|
71
|
+
const active = context.active();
|
|
72
|
+
return trace.getSpan(active) === undefined ? undefined : new OpenTelemetrySpan(active);
|
|
73
|
+
}
|
|
74
|
+
withActiveSpan(span, fn) {
|
|
75
|
+
return context.with(contextOf(span), fn);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* No span, or a span of another tracer (e.g. one set while a request was running), falls back to the active context.
|
|
80
|
+
*/
|
|
81
|
+
function contextOf(span) {
|
|
82
|
+
return span instanceof OpenTelemetrySpan ? span.context : context.active();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The baggage propagator replaces the baggage of the context it extracts into,
|
|
86
|
+
* so entries already set (e.g. by an HTTP instrumentation or middleware) are added back, and win on conflict.
|
|
87
|
+
*/
|
|
88
|
+
function withActiveBaggage(extracted, active) {
|
|
89
|
+
const fromHeaders = propagation.getBaggage(extracted);
|
|
90
|
+
const current = propagation.getBaggage(active);
|
|
91
|
+
if (fromHeaders === undefined || current === undefined || fromHeaders === current) {
|
|
92
|
+
return extracted;
|
|
93
|
+
}
|
|
94
|
+
return propagation.setBaggage(extracted, propagation.createBaggage(Object.fromEntries([...fromHeaders.getAllEntries(), ...current.getAllEntries()])));
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/opentelemetry",
|
|
3
|
-
"
|
|
4
|
-
"version": "2.0.0-beta.47",
|
|
3
|
+
"version": "2.0.0-beta.49",
|
|
5
4
|
"description": "OpenTelemetry integration for oRPC: distributed tracing for typesafe APIs",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"observability",
|
|
7
|
+
"opentelemetry",
|
|
8
|
+
"orpc",
|
|
9
|
+
"otel",
|
|
10
|
+
"tracing",
|
|
11
|
+
"typescript"
|
|
10
12
|
],
|
|
11
13
|
"homepage": "https://orpc.dev",
|
|
14
|
+
"license": "MIT",
|
|
12
15
|
"repository": {
|
|
13
16
|
"type": "git",
|
|
14
17
|
"url": "git+https://github.com/middleapi/orpc.git",
|
|
15
18
|
"directory": "packages/opentelemetry"
|
|
16
19
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"typescript"
|
|
20
|
+
"funding": [
|
|
21
|
+
"https://github.com/sponsors/dinwwwh",
|
|
22
|
+
"https://opencollective.com/middleapi"
|
|
23
|
+
],
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
24
26
|
],
|
|
27
|
+
"type": "module",
|
|
25
28
|
"sideEffects": false,
|
|
26
29
|
"exports": {
|
|
27
30
|
"./package.json": "./package.json",
|
|
28
31
|
".": {
|
|
29
|
-
"types": "./dist/index.d.
|
|
30
|
-
"import": "./dist/index.
|
|
31
|
-
"default": "./dist/index.
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
32
35
|
}
|
|
33
36
|
},
|
|
34
|
-
"files": [
|
|
35
|
-
"dist"
|
|
36
|
-
],
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"@opentelemetry/api": ">=1.9.0",
|
|
39
|
-
"@opentelemetry/instrumentation": ">=0.203.0"
|
|
40
|
-
},
|
|
41
37
|
"dependencies": {
|
|
42
|
-
"@orpc/shared": "2.0.0-beta.
|
|
38
|
+
"@orpc/shared": "2.0.0-beta.49"
|
|
43
39
|
},
|
|
44
40
|
"devDependencies": {
|
|
45
|
-
"@opentelemetry/api": "^1.
|
|
46
|
-
"@opentelemetry/instrumentation": "^0.
|
|
41
|
+
"@opentelemetry/api": "^1.10.0",
|
|
42
|
+
"@opentelemetry/instrumentation": "^0.300.0",
|
|
47
43
|
"@opentelemetry/sdk-trace-node": "^2.12.0"
|
|
48
44
|
},
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@opentelemetry/api": ">=1.9.0",
|
|
47
|
+
"@opentelemetry/instrumentation": ">=0.203.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {}
|
|
52
50
|
}
|
package/dist/index.d.mts
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 };
|
package/dist/index.mjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
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.47";
|
|
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 };
|