@sophonz/node-sdk 0.0.1
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/LICENSE +15 -0
- package/README.md +118 -0
- package/build/bin/opentelemetry-instrument.d.ts +3 -0
- package/build/bin/opentelemetry-instrument.d.ts.map +1 -0
- package/build/bin/opentelemetry-instrument.js +21 -0
- package/build/package.json +62 -0
- package/build/src/AbstractAsyncHooksContextManager.d.ts +18 -0
- package/build/src/AbstractAsyncHooksContextManager.d.ts.map +1 -0
- package/build/src/AbstractAsyncHooksContextManager.js +122 -0
- package/build/src/MutableAsyncLocalStorageContextManager.d.ts +14 -0
- package/build/src/MutableAsyncLocalStorageContextManager.d.ts.map +1 -0
- package/build/src/MutableAsyncLocalStorageContextManager.js +36 -0
- package/build/src/constants.d.ts +27 -0
- package/build/src/constants.d.ts.map +1 -0
- package/build/src/constants.js +41 -0
- package/build/src/gcp.d.ts +3 -0
- package/build/src/gcp.d.ts.map +1 -0
- package/build/src/gcp.js +60 -0
- package/build/src/index.d.ts +6 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +11 -0
- package/build/src/instrumentations/console.d.ts +24 -0
- package/build/src/instrumentations/console.d.ts.map +1 -0
- package/build/src/instrumentations/console.js +146 -0
- package/build/src/instrumentations/http.d.ts +21 -0
- package/build/src/instrumentations/http.d.ts.map +1 -0
- package/build/src/instrumentations/http.js +285 -0
- package/build/src/logger.d.ts +26 -0
- package/build/src/logger.d.ts.map +1 -0
- package/build/src/logger.js +54 -0
- package/build/src/metrics.d.ts +3 -0
- package/build/src/metrics.d.ts.map +1 -0
- package/build/src/metrics.js +14 -0
- package/build/src/otel-logger/index.d.ts +36 -0
- package/build/src/otel-logger/index.d.ts.map +1 -0
- package/build/src/otel-logger/index.js +104 -0
- package/build/src/otel-logger/pino.d.ts +37 -0
- package/build/src/otel-logger/pino.d.ts.map +1 -0
- package/build/src/otel-logger/pino.js +91 -0
- package/build/src/otel-logger/winston.d.ts +29 -0
- package/build/src/otel-logger/winston.d.ts.map +1 -0
- package/build/src/otel-logger/winston.js +72 -0
- package/build/src/otel.d.ts +29 -0
- package/build/src/otel.d.ts.map +1 -0
- package/build/src/otel.js +482 -0
- package/build/src/spanProcessor.d.ts +17 -0
- package/build/src/spanProcessor.d.ts.map +1 -0
- package/build/src/spanProcessor.js +37 -0
- package/build/src/tracing.d.ts +2 -0
- package/build/src/tracing.d.ts.map +1 -0
- package/build/src/tracing.js +4 -0
- package/build/src/utils.d.ts +3 -0
- package/build/src/utils.d.ts.map +1 -0
- package/build/src/utils.js +32 -0
- package/build/src/version.d.ts +2 -0
- package/build/src/version.d.ts.map +1 -0
- package/build/src/version.js +4 -0
- package/package.json +62 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const api_logs_1 = require("@opentelemetry/api-logs");
|
|
6
|
+
const core_1 = require("@opentelemetry/core");
|
|
7
|
+
const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
|
|
8
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
9
|
+
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
10
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
11
|
+
class NoopLogRecordProcessor {
|
|
12
|
+
onEmit() {
|
|
13
|
+
}
|
|
14
|
+
forceFlush() {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
shutdown() {
|
|
18
|
+
return Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const package_json_1 = require("../../package.json");
|
|
22
|
+
const constants_1 = require("../constants");
|
|
23
|
+
const LOG_PREFIX = `⚠️ [LOGGER]`;
|
|
24
|
+
class Logger {
|
|
25
|
+
constructor({ baseUrl, bufferSize, detectResource = true, headers, queueSize, resourceAttributes, sendIntervalMs, service, timeout, }) {
|
|
26
|
+
const _serviceName = (0, constants_1.DEFAULT_SERVICE_NAME)();
|
|
27
|
+
if (!service) {
|
|
28
|
+
api_1.diag.warn(`${LOG_PREFIX} Service name not found. Use "${_serviceName}"`);
|
|
29
|
+
}
|
|
30
|
+
const maxExportBatchSize = bufferSize !== null && bufferSize !== void 0 ? bufferSize : constants_1.DEFAULT_EXPORTER_BATCH_SIZE;
|
|
31
|
+
let maxQueueSize = queueSize !== null && queueSize !== void 0 ? queueSize : constants_1.DEFAULT_MAX_QUEUE_SIZE;
|
|
32
|
+
if (maxExportBatchSize > maxQueueSize) {
|
|
33
|
+
api_1.diag.error(`${LOG_PREFIX} bufferSize must be smaller or equal to queueSize. Setting queueSize to ${maxExportBatchSize}`);
|
|
34
|
+
maxQueueSize = maxExportBatchSize;
|
|
35
|
+
}
|
|
36
|
+
const detectedResource = (0, resources_1.detectResources)({
|
|
37
|
+
detectors: detectResource
|
|
38
|
+
? [resources_1.envDetector, resources_1.hostDetector, resources_1.osDetector, resources_1.processDetector]
|
|
39
|
+
: [],
|
|
40
|
+
});
|
|
41
|
+
this._url = baseUrl !== null && baseUrl !== void 0 ? baseUrl : constants_1.DEFAULT_OTEL_LOGS_EXPORTER_URL;
|
|
42
|
+
api_1.diag.warn(`${LOG_PREFIX} Sending logs to ${this._url}`);
|
|
43
|
+
const exporter = new exporter_logs_otlp_http_1.OTLPLogExporter({
|
|
44
|
+
url: this._url,
|
|
45
|
+
...(headers && { headers }),
|
|
46
|
+
});
|
|
47
|
+
this.processor = this.isDisabled()
|
|
48
|
+
? new NoopLogRecordProcessor()
|
|
49
|
+
: new sdk_logs_1.BatchLogRecordProcessor(exporter, {
|
|
50
|
+
maxExportBatchSize,
|
|
51
|
+
scheduledDelayMillis: sendIntervalMs !== null && sendIntervalMs !== void 0 ? sendIntervalMs : constants_1.DEFAULT_SEND_INTERVAL_MS,
|
|
52
|
+
exportTimeoutMillis: timeout !== null && timeout !== void 0 ? timeout : constants_1.DEFAULT_EXPORTER_TIMEOUT_MS,
|
|
53
|
+
maxQueueSize,
|
|
54
|
+
});
|
|
55
|
+
this.provider = new sdk_logs_1.LoggerProvider({
|
|
56
|
+
resource: detectedResource.merge((0, resources_1.resourceFromAttributes)({
|
|
57
|
+
'sophonz.distro.version': package_json_1.version,
|
|
58
|
+
[semantic_conventions_1.SEMRESATTRS_SERVICE_NAME]: service !== null && service !== void 0 ? service : _serviceName,
|
|
59
|
+
...resourceAttributes,
|
|
60
|
+
})),
|
|
61
|
+
});
|
|
62
|
+
this.logger = this.provider.getLogger('node-logger');
|
|
63
|
+
}
|
|
64
|
+
parseTimestamp(meta) {
|
|
65
|
+
if (Number.isInteger(meta.time)) {
|
|
66
|
+
return new Date(meta.time);
|
|
67
|
+
}
|
|
68
|
+
return new Date();
|
|
69
|
+
}
|
|
70
|
+
isDisabled() {
|
|
71
|
+
return (0, core_1.getStringFromEnv)('OTEL_LOGS_EXPORTER') === 'none';
|
|
72
|
+
}
|
|
73
|
+
setGlobalLoggerProvider() {
|
|
74
|
+
api_1.diag.debug('Setting global logger provider...');
|
|
75
|
+
api_logs_1.logs.setGlobalLoggerProvider(this.provider);
|
|
76
|
+
}
|
|
77
|
+
getExporterUrl() {
|
|
78
|
+
return this._url;
|
|
79
|
+
}
|
|
80
|
+
getProvider() {
|
|
81
|
+
return this.provider;
|
|
82
|
+
}
|
|
83
|
+
getProcessor() {
|
|
84
|
+
return this.processor;
|
|
85
|
+
}
|
|
86
|
+
shutdown() {
|
|
87
|
+
api_1.diag.debug('Shutting down Sophonz node logger...');
|
|
88
|
+
return this.processor.shutdown();
|
|
89
|
+
}
|
|
90
|
+
forceFlush() {
|
|
91
|
+
api_1.diag.debug('Forcing flush of Sophonz node logger...');
|
|
92
|
+
return this.processor.forceFlush();
|
|
93
|
+
}
|
|
94
|
+
postMessage(level, body, attributes = {}) {
|
|
95
|
+
this.logger.emit({
|
|
96
|
+
severityNumber: 0,
|
|
97
|
+
severityText: level,
|
|
98
|
+
body,
|
|
99
|
+
attributes,
|
|
100
|
+
timestamp: this.parseTimestamp(attributes),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Attributes } from '@opentelemetry/api';
|
|
2
|
+
import build from 'pino-abstract-transport';
|
|
3
|
+
import type { LoggerOptions } from './';
|
|
4
|
+
export type PinoLogLine = {
|
|
5
|
+
level: number;
|
|
6
|
+
time: number;
|
|
7
|
+
pid: number;
|
|
8
|
+
hostname: string;
|
|
9
|
+
msg: string;
|
|
10
|
+
} & Attributes;
|
|
11
|
+
export declare const parsePinoLog: (log: PinoLogLine) => {
|
|
12
|
+
level: number;
|
|
13
|
+
message: string;
|
|
14
|
+
meta: {
|
|
15
|
+
[attributeKey: string]: import("@opentelemetry/api").AttributeValue;
|
|
16
|
+
time: number;
|
|
17
|
+
pid: number;
|
|
18
|
+
hostname: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type SophonzPinoOptions = LoggerOptions & {
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
getCustomMeta?: () => Attributes;
|
|
24
|
+
};
|
|
25
|
+
declare const DEFAULT_LOG_KEYS: {
|
|
26
|
+
traceId: string;
|
|
27
|
+
spanId: string;
|
|
28
|
+
traceFlags: string;
|
|
29
|
+
};
|
|
30
|
+
export declare const getMixinFunction: () => {
|
|
31
|
+
[DEFAULT_LOG_KEYS.traceId]: string;
|
|
32
|
+
[DEFAULT_LOG_KEYS.spanId]: string;
|
|
33
|
+
[DEFAULT_LOG_KEYS.traceFlags]: string;
|
|
34
|
+
};
|
|
35
|
+
declare const _default: ({ apiKey, getCustomMeta, ...options }: SophonzPinoOptions) => Promise<import("node:stream").Transform & build.OnUnknown>;
|
|
36
|
+
export default _default;
|
|
37
|
+
//# sourceMappingURL=pino.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pino.d.ts","sourceRoot":"","sources":["../../../src/otel-logger/pino.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAKX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAG5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAGxC,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,UAAU,CAAC;AAEf,eAAO,MAAM,YAAY,GAAI,KAAK,WAAW;;;;;cANrC,MAAM;aACP,MAAM;kBACD,MAAM;;CAoBjB,CAAC;AAYF,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,UAAU,CAAC;CAClC,CAAC;AAGF,QAAA,MAAM,gBAAgB;;;;CAIrB,CAAC;AACF,eAAO,MAAM,gBAAgB;IAYzB,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAqB;IAC/C,CAAC,gBAAgB,CAAC,MAAM,CAAC,SAAoB;IAC7C,CAAC,gBAAgB,CAAC,UAAU,CAAC,SAA2C;CAE3E,CAAC;yBAEoB,uCAInB,kBAAkB;AAJrB,wBAwCE"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMixinFunction = exports.parsePinoLog = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_1 = require("@opentelemetry/api");
|
|
6
|
+
const lodash_isstring_1 = tslib_1.__importDefault(require("lodash.isstring"));
|
|
7
|
+
const pino_abstract_transport_1 = tslib_1.__importDefault(require("pino-abstract-transport"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const _1 = require("./");
|
|
10
|
+
const parsePinoLog = (log) => {
|
|
11
|
+
const { level, msg, message, ...meta } = log;
|
|
12
|
+
const targetMessage = msg || message;
|
|
13
|
+
let bodyMsg = '';
|
|
14
|
+
if (targetMessage) {
|
|
15
|
+
bodyMsg = (0, lodash_isstring_1.default)(targetMessage)
|
|
16
|
+
? targetMessage
|
|
17
|
+
: (0, utils_1.jsonToString)(targetMessage);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
bodyMsg = (0, utils_1.jsonToString)(log);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
level,
|
|
24
|
+
message: bodyMsg,
|
|
25
|
+
meta,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.parsePinoLog = parsePinoLog;
|
|
29
|
+
const PINO_LEVELS = {
|
|
30
|
+
10: 'trace',
|
|
31
|
+
20: 'debug',
|
|
32
|
+
30: 'info',
|
|
33
|
+
40: 'warn',
|
|
34
|
+
50: 'error',
|
|
35
|
+
60: 'fatal',
|
|
36
|
+
};
|
|
37
|
+
const DEFAULT_LOG_KEYS = {
|
|
38
|
+
traceId: 'trace_id',
|
|
39
|
+
spanId: 'span_id',
|
|
40
|
+
traceFlags: 'trace_flags',
|
|
41
|
+
};
|
|
42
|
+
const getMixinFunction = () => {
|
|
43
|
+
const span = api_1.trace.getSpan(api_1.context.active());
|
|
44
|
+
if (!span) {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
const spanContext = span.spanContext();
|
|
48
|
+
if (!(0, api_1.isSpanContextValid)(spanContext)) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
[DEFAULT_LOG_KEYS.traceId]: spanContext.traceId,
|
|
53
|
+
[DEFAULT_LOG_KEYS.spanId]: spanContext.spanId,
|
|
54
|
+
[DEFAULT_LOG_KEYS.traceFlags]: `0${spanContext.traceFlags.toString(16)}`,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.getMixinFunction = getMixinFunction;
|
|
58
|
+
exports.default = async ({ apiKey, getCustomMeta, ...options }) => {
|
|
59
|
+
try {
|
|
60
|
+
api_1.diag.debug('Initializing Sophonz pino transport...');
|
|
61
|
+
const logger = new _1.Logger({
|
|
62
|
+
...(apiKey && {
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: apiKey,
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
...options,
|
|
68
|
+
});
|
|
69
|
+
api_1.diag.debug(`Sophonz pino transport initialized!`);
|
|
70
|
+
return (0, pino_abstract_transport_1.default)(async function (source) {
|
|
71
|
+
for await (const obj of source) {
|
|
72
|
+
const { level, message, meta } = (0, exports.parsePinoLog)(obj);
|
|
73
|
+
api_1.diag.debug('Sending log to Sophonz');
|
|
74
|
+
logger.postMessage(PINO_LEVELS[level], message, {
|
|
75
|
+
...getCustomMeta === null || getCustomMeta === void 0 ? void 0 : getCustomMeta(),
|
|
76
|
+
...meta,
|
|
77
|
+
});
|
|
78
|
+
api_1.diag.debug('Log sent to Sophonz');
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
async close(err) {
|
|
82
|
+
api_1.diag.debug('Sending and closing Sophonz pino transport...');
|
|
83
|
+
await logger.shutdown();
|
|
84
|
+
api_1.diag.debug('Sophonz pino transport closed!');
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
api_1.diag.error('createTransport error', err);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Attributes } from '@opentelemetry/api';
|
|
2
|
+
import Transport from 'winston-transport';
|
|
3
|
+
import type { LoggerOptions } from './';
|
|
4
|
+
export declare const parseWinstonLog: (log: {
|
|
5
|
+
message: string | Attributes;
|
|
6
|
+
level: string;
|
|
7
|
+
} & Attributes) => {
|
|
8
|
+
level: string;
|
|
9
|
+
message: string;
|
|
10
|
+
meta: {
|
|
11
|
+
[attributeKey: string]: import("@opentelemetry/api").AttributeValue;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type SophonzWinstonOptions = LoggerOptions & {
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
maxLevel?: string;
|
|
17
|
+
getCustomMeta?: () => Attributes;
|
|
18
|
+
};
|
|
19
|
+
export default class SophonzWinston extends Transport {
|
|
20
|
+
private readonly logger;
|
|
21
|
+
private readonly getCustomMeta;
|
|
22
|
+
constructor({ maxLevel, getCustomMeta, apiKey, ...options }: SophonzWinstonOptions);
|
|
23
|
+
log(info: {
|
|
24
|
+
message: string | Attributes;
|
|
25
|
+
level: string;
|
|
26
|
+
} & Attributes, callback: () => void): void;
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=winston.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston.d.ts","sourceRoot":"","sources":["../../../src/otel-logger/winston.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,oBAAoB,CAAC;AAGtD,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAG1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAGxC,eAAO,MAAM,eAAe,GAC1B,KAAK;IACH,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU;;;;;;CAoBf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,UAAU,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,SAAS;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiC;gBAEnD,EACV,QAAQ,EACR,aAAa,EACb,MAAM,EACN,GAAG,OAAO,EACX,EAAE,qBAAqB;IAexB,GAAG,CACD,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,EAClE,QAAQ,EAAE,MAAM,IAAI;IAmBtB,KAAK;CAaN"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseWinstonLog = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_1 = require("@opentelemetry/api");
|
|
6
|
+
const lodash_isplainobject_1 = tslib_1.__importDefault(require("lodash.isplainobject"));
|
|
7
|
+
const lodash_isstring_1 = tslib_1.__importDefault(require("lodash.isstring"));
|
|
8
|
+
const winston_transport_1 = tslib_1.__importDefault(require("winston-transport"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const _1 = require("./");
|
|
11
|
+
const parseWinstonLog = (log) => {
|
|
12
|
+
const { level, message, ...attributes } = log;
|
|
13
|
+
const bodyMsg = (0, lodash_isstring_1.default)(message) ? message : (0, utils_1.jsonToString)(message);
|
|
14
|
+
let meta = attributes;
|
|
15
|
+
if ((0, lodash_isplainobject_1.default)(message)) {
|
|
16
|
+
meta = {
|
|
17
|
+
...attributes,
|
|
18
|
+
...message,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
level,
|
|
23
|
+
message: bodyMsg,
|
|
24
|
+
meta,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.parseWinstonLog = parseWinstonLog;
|
|
28
|
+
class SophonzWinston extends winston_transport_1.default {
|
|
29
|
+
constructor({ maxLevel, getCustomMeta, apiKey, ...options }) {
|
|
30
|
+
api_1.diag.debug('Initializing Sophonz winston transport...');
|
|
31
|
+
super({ level: maxLevel !== null && maxLevel !== void 0 ? maxLevel : 'info' });
|
|
32
|
+
this.getCustomMeta = getCustomMeta;
|
|
33
|
+
this.logger = new _1.Logger({
|
|
34
|
+
...(apiKey && {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: apiKey,
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
...options,
|
|
40
|
+
});
|
|
41
|
+
api_1.diag.debug(`Sophonz winston transport initialized!`);
|
|
42
|
+
}
|
|
43
|
+
log(info, callback) {
|
|
44
|
+
var _a;
|
|
45
|
+
setImmediate(() => {
|
|
46
|
+
this.emit('logged', info);
|
|
47
|
+
});
|
|
48
|
+
api_1.diag.debug('Received log from winston');
|
|
49
|
+
const { level, message, meta } = (0, exports.parseWinstonLog)(info);
|
|
50
|
+
api_1.diag.debug('Sending log to Sophonz');
|
|
51
|
+
this.logger.postMessage(level, message, {
|
|
52
|
+
...(_a = this.getCustomMeta) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
53
|
+
...meta,
|
|
54
|
+
});
|
|
55
|
+
api_1.diag.debug('Log sent to Sophonz');
|
|
56
|
+
callback();
|
|
57
|
+
}
|
|
58
|
+
close() {
|
|
59
|
+
api_1.diag.debug('Closing Sophonz winston transport...');
|
|
60
|
+
this.logger
|
|
61
|
+
.shutdown()
|
|
62
|
+
.then(() => {
|
|
63
|
+
api_1.diag.debug('Sophonz winston transport closed!');
|
|
64
|
+
this.emit('finish');
|
|
65
|
+
this.emit('close');
|
|
66
|
+
})
|
|
67
|
+
.catch((err) => {
|
|
68
|
+
api_1.diag.error('Error closing Sophonz winston transport:', err);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = SophonzWinston;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Attributes } from '@opentelemetry/api';
|
|
2
|
+
import { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';
|
|
3
|
+
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
4
|
+
import { MetricReader } from '@opentelemetry/sdk-metrics';
|
|
5
|
+
export type SDKConfig = {
|
|
6
|
+
additionalInstrumentations?: InstrumentationBase[];
|
|
7
|
+
advancedNetworkCapture?: boolean;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
betaMode?: boolean;
|
|
10
|
+
consoleCapture?: boolean;
|
|
11
|
+
detectResources?: boolean;
|
|
12
|
+
disableLogs?: boolean;
|
|
13
|
+
disableMetrics?: boolean;
|
|
14
|
+
disableStartupLogs?: boolean;
|
|
15
|
+
disableTracing?: boolean;
|
|
16
|
+
enableInternalProfiling?: boolean;
|
|
17
|
+
experimentalExceptionCapture?: boolean;
|
|
18
|
+
instrumentations?: InstrumentationConfigMap;
|
|
19
|
+
metricReader?: MetricReader;
|
|
20
|
+
programmaticImports?: boolean;
|
|
21
|
+
sentryIntegrationEnabled?: boolean;
|
|
22
|
+
service?: string;
|
|
23
|
+
stopOnTerminationSignals?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const initSDK: (config: SDKConfig) => void;
|
|
26
|
+
export declare const init: (config?: Omit<SDKConfig, "programmaticImports">) => void;
|
|
27
|
+
export declare const shutdown: () => Promise<void>;
|
|
28
|
+
export declare const setTraceAttributes: (attributes: Attributes) => void;
|
|
29
|
+
//# sourceMappingURL=otel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../src/otel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAEL,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EACL,mBAAmB,EAEpB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AA4C1D,MAAM,MAAM,SAAS,GAAG;IACtB,0BAA0B,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnD,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;IAC5C,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAgGF,eAAO,MAAM,OAAO,GAAI,QAAQ,SAAS,SAmexC,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,SAAS,IAAI,CAAC,SAAS,EAAE,qBAAqB,CAAC,SAOhE,CAAC;AAmBL,eAAO,MAAM,QAAQ,qBAGpB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,YAAY,UAAU,SAexD,CAAC"}
|