@contello/opentelemetry 1.0.0
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/dist/index.cjs +128 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +91 -0
- package/package.json +41 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ContelloInstrumentation: () => ContelloInstrumentation
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/wrap.ts
|
|
38
|
+
var import_node_diagnostics_channel = __toESM(require("diagnostics_channel"), 1);
|
|
39
|
+
var import_api = require("@opentelemetry/api");
|
|
40
|
+
var import_instrumentation = require("@opentelemetry/instrumentation");
|
|
41
|
+
function parseMetricAttrs(name, extra) {
|
|
42
|
+
const colonIndex = name.indexOf(":");
|
|
43
|
+
if (colonIndex === -1) {
|
|
44
|
+
return { category: "unknown", operation: name, ...extra };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
category: name.slice(0, colonIndex),
|
|
48
|
+
operation: name.slice(colonIndex + 1),
|
|
49
|
+
...extra
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var CHANNEL_PREFIXES = ["contello:store", "contello:sdk", "contello:astro"];
|
|
53
|
+
var ContelloInstrumentation = class extends import_instrumentation.InstrumentationBase {
|
|
54
|
+
_subscriptions = [];
|
|
55
|
+
constructor(config = {}) {
|
|
56
|
+
super("@contello/opentelemetry", "0.0.0", config);
|
|
57
|
+
}
|
|
58
|
+
init() {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
enable() {
|
|
62
|
+
if (this._subscriptions.length > 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const tracer = this.tracer;
|
|
66
|
+
const meter = this.meter;
|
|
67
|
+
const durationHistogram = meter.createHistogram("contello.operation.duration", {
|
|
68
|
+
description: "Duration of contello operations",
|
|
69
|
+
unit: "ms"
|
|
70
|
+
});
|
|
71
|
+
const errorCounter = meter.createCounter("contello.operation.error", {
|
|
72
|
+
description: "Number of failed contello operations"
|
|
73
|
+
});
|
|
74
|
+
const userConfig = this.getConfig();
|
|
75
|
+
for (const prefix of CHANNEL_PREFIXES) {
|
|
76
|
+
const endChannel = import_node_diagnostics_channel.default.channel(`${prefix}.end`);
|
|
77
|
+
const errorChannel = import_node_diagnostics_channel.default.channel(`${prefix}.error`);
|
|
78
|
+
const onEnd = (message) => {
|
|
79
|
+
const msg = message;
|
|
80
|
+
const attrs = parseMetricAttrs(msg.name, { cached: msg.cached ?? false });
|
|
81
|
+
durationHistogram.record(msg.durationMs, attrs);
|
|
82
|
+
userConfig?.onComplete?.(msg.name, msg.durationMs);
|
|
83
|
+
const span = tracer.startSpan(msg.name);
|
|
84
|
+
span.setAttributes(attrs);
|
|
85
|
+
span.end();
|
|
86
|
+
};
|
|
87
|
+
const onError = (message) => {
|
|
88
|
+
const msg = message;
|
|
89
|
+
const attrs = parseMetricAttrs(msg.name, { cached: false });
|
|
90
|
+
durationHistogram.record(msg.durationMs, attrs);
|
|
91
|
+
errorCounter.add(1, attrs);
|
|
92
|
+
userConfig?.onError?.(msg.name, msg.error);
|
|
93
|
+
const span = tracer.startSpan(msg.name);
|
|
94
|
+
span.setAttributes(attrs);
|
|
95
|
+
span.recordException(msg.error);
|
|
96
|
+
span.end();
|
|
97
|
+
};
|
|
98
|
+
endChannel.subscribe(onEnd);
|
|
99
|
+
errorChannel.subscribe(onError);
|
|
100
|
+
this._subscriptions.push({ channel: endChannel, handler: onEnd });
|
|
101
|
+
this._subscriptions.push({ channel: errorChannel, handler: onError });
|
|
102
|
+
}
|
|
103
|
+
const messageChannel = import_node_diagnostics_channel.default.channel("contello:sdk.message");
|
|
104
|
+
const onMessage = (message) => {
|
|
105
|
+
const msg = message;
|
|
106
|
+
const output = {};
|
|
107
|
+
import_api.propagation.inject(import_api.context.active(), output);
|
|
108
|
+
if (output["traceparent"]) {
|
|
109
|
+
msg.message.traceparent = output["traceparent"];
|
|
110
|
+
}
|
|
111
|
+
if (output["tracestate"]) {
|
|
112
|
+
msg.message.tracestate = output["tracestate"];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
messageChannel.subscribe(onMessage);
|
|
116
|
+
this._subscriptions.push({ channel: messageChannel, handler: onMessage });
|
|
117
|
+
}
|
|
118
|
+
disable() {
|
|
119
|
+
for (const { channel, handler } of this._subscriptions) {
|
|
120
|
+
channel.unsubscribe(handler);
|
|
121
|
+
}
|
|
122
|
+
this._subscriptions = [];
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
ContelloInstrumentation
|
|
128
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InstrumentationConfig, InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
2
|
+
|
|
3
|
+
type ContelloInstrumentationConfig = InstrumentationConfig & {
|
|
4
|
+
onComplete?: ((name: string, durationMs: number) => void) | undefined;
|
|
5
|
+
onError?: ((name: string, error: unknown) => void) | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare class ContelloInstrumentation extends InstrumentationBase<ContelloInstrumentationConfig> {
|
|
9
|
+
private _subscriptions;
|
|
10
|
+
constructor(config?: ContelloInstrumentationConfig);
|
|
11
|
+
init(): never[];
|
|
12
|
+
enable(): void;
|
|
13
|
+
disable(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { ContelloInstrumentation, type ContelloInstrumentationConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InstrumentationConfig, InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
2
|
+
|
|
3
|
+
type ContelloInstrumentationConfig = InstrumentationConfig & {
|
|
4
|
+
onComplete?: ((name: string, durationMs: number) => void) | undefined;
|
|
5
|
+
onError?: ((name: string, error: unknown) => void) | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare class ContelloInstrumentation extends InstrumentationBase<ContelloInstrumentationConfig> {
|
|
9
|
+
private _subscriptions;
|
|
10
|
+
constructor(config?: ContelloInstrumentationConfig);
|
|
11
|
+
init(): never[];
|
|
12
|
+
enable(): void;
|
|
13
|
+
disable(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { ContelloInstrumentation, type ContelloInstrumentationConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/wrap.ts
|
|
2
|
+
import dc from "diagnostics_channel";
|
|
3
|
+
import { context, propagation } from "@opentelemetry/api";
|
|
4
|
+
import { InstrumentationBase } from "@opentelemetry/instrumentation";
|
|
5
|
+
function parseMetricAttrs(name, extra) {
|
|
6
|
+
const colonIndex = name.indexOf(":");
|
|
7
|
+
if (colonIndex === -1) {
|
|
8
|
+
return { category: "unknown", operation: name, ...extra };
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
category: name.slice(0, colonIndex),
|
|
12
|
+
operation: name.slice(colonIndex + 1),
|
|
13
|
+
...extra
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var CHANNEL_PREFIXES = ["contello:store", "contello:sdk", "contello:astro"];
|
|
17
|
+
var ContelloInstrumentation = class extends InstrumentationBase {
|
|
18
|
+
_subscriptions = [];
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
super("@contello/opentelemetry", "0.0.0", config);
|
|
21
|
+
}
|
|
22
|
+
init() {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
enable() {
|
|
26
|
+
if (this._subscriptions.length > 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const tracer = this.tracer;
|
|
30
|
+
const meter = this.meter;
|
|
31
|
+
const durationHistogram = meter.createHistogram("contello.operation.duration", {
|
|
32
|
+
description: "Duration of contello operations",
|
|
33
|
+
unit: "ms"
|
|
34
|
+
});
|
|
35
|
+
const errorCounter = meter.createCounter("contello.operation.error", {
|
|
36
|
+
description: "Number of failed contello operations"
|
|
37
|
+
});
|
|
38
|
+
const userConfig = this.getConfig();
|
|
39
|
+
for (const prefix of CHANNEL_PREFIXES) {
|
|
40
|
+
const endChannel = dc.channel(`${prefix}.end`);
|
|
41
|
+
const errorChannel = dc.channel(`${prefix}.error`);
|
|
42
|
+
const onEnd = (message) => {
|
|
43
|
+
const msg = message;
|
|
44
|
+
const attrs = parseMetricAttrs(msg.name, { cached: msg.cached ?? false });
|
|
45
|
+
durationHistogram.record(msg.durationMs, attrs);
|
|
46
|
+
userConfig?.onComplete?.(msg.name, msg.durationMs);
|
|
47
|
+
const span = tracer.startSpan(msg.name);
|
|
48
|
+
span.setAttributes(attrs);
|
|
49
|
+
span.end();
|
|
50
|
+
};
|
|
51
|
+
const onError = (message) => {
|
|
52
|
+
const msg = message;
|
|
53
|
+
const attrs = parseMetricAttrs(msg.name, { cached: false });
|
|
54
|
+
durationHistogram.record(msg.durationMs, attrs);
|
|
55
|
+
errorCounter.add(1, attrs);
|
|
56
|
+
userConfig?.onError?.(msg.name, msg.error);
|
|
57
|
+
const span = tracer.startSpan(msg.name);
|
|
58
|
+
span.setAttributes(attrs);
|
|
59
|
+
span.recordException(msg.error);
|
|
60
|
+
span.end();
|
|
61
|
+
};
|
|
62
|
+
endChannel.subscribe(onEnd);
|
|
63
|
+
errorChannel.subscribe(onError);
|
|
64
|
+
this._subscriptions.push({ channel: endChannel, handler: onEnd });
|
|
65
|
+
this._subscriptions.push({ channel: errorChannel, handler: onError });
|
|
66
|
+
}
|
|
67
|
+
const messageChannel = dc.channel("contello:sdk.message");
|
|
68
|
+
const onMessage = (message) => {
|
|
69
|
+
const msg = message;
|
|
70
|
+
const output = {};
|
|
71
|
+
propagation.inject(context.active(), output);
|
|
72
|
+
if (output["traceparent"]) {
|
|
73
|
+
msg.message.traceparent = output["traceparent"];
|
|
74
|
+
}
|
|
75
|
+
if (output["tracestate"]) {
|
|
76
|
+
msg.message.tracestate = output["tracestate"];
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
messageChannel.subscribe(onMessage);
|
|
80
|
+
this._subscriptions.push({ channel: messageChannel, handler: onMessage });
|
|
81
|
+
}
|
|
82
|
+
disable() {
|
|
83
|
+
for (const { channel, handler } of this._subscriptions) {
|
|
84
|
+
channel.unsubscribe(handler);
|
|
85
|
+
}
|
|
86
|
+
this._subscriptions = [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
ContelloInstrumentation
|
|
91
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contello/opentelemetry",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenTelemetry instrumentation for Contello packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "admin@entwico.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/entwico/contello-js",
|
|
11
|
+
"directory": "packages/opentelemetry"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"lint": "eslint .",
|
|
16
|
+
"lint:fix": "eslint . --fix",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@opentelemetry/api": ">=1.0.0",
|
|
21
|
+
"@opentelemetry/instrumentation": ">=0.200.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@opentelemetry/api": "^1.9.0",
|
|
25
|
+
"@opentelemetry/instrumentation": "^0.213.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org"
|
|
40
|
+
}
|
|
41
|
+
}
|