@orpc/opentelemetry 2.0.0-beta.47 → 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 +2 -3
- package/dist/index.d.mts +1 -27
- package/dist/index.mjs +1 -100
- package/dist/instrumentation.d.mts +24 -0
- package/dist/instrumentation.mjs +23 -0
- package/dist/tracer.d.mts +36 -0
- package/dist/tracer.mjs +71 -0
- package/package.json +4 -4
- package/dist/index.d.ts +0 -27
package/README.md
CHANGED
|
@@ -191,15 +191,14 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
191
191
|
<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
192
|
<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
193
|
<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://
|
|
194
|
+
<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
195
|
</tr>
|
|
196
196
|
<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
197
|
<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
198
|
</tr>
|
|
200
199
|
</table>
|
|
201
200
|
|
|
202
|
-
With thanks to [
|
|
201
|
+
With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
203
202
|
|
|
204
203
|
## Open Source Programs
|
|
205
204
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1 @@
|
|
|
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.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1,100 +1 @@
|
|
|
1
|
-
|
|
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 };
|
|
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
|
+
}
|
package/dist/tracer.mjs
ADDED
|
@@ -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.
|
|
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.
|
|
42
|
+
"@orpc/shared": "2.0.0-beta.48"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@opentelemetry/api": "^1.
|
|
46
|
-
"@opentelemetry/instrumentation": "^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 };
|