@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
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) 2024-2025 INOBS Inc. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the proprietary property of INOBS Inc. and are protected by copyright and other intellectual property laws.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, on a limited basis, to use, copy, modify, or distribute the Software only within the scope of a separate written license agreement with INOBS Inc.
|
|
6
|
+
|
|
7
|
+
Unless otherwise agreed to in writing, the Software shall not be used, reproduced, distributed, sublicensed, or disclosed, in whole or in part, to any third party.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
10
|
+
|
|
11
|
+
For license inquiries, please contact:
|
|
12
|
+
|
|
13
|
+
INOBS Inc.
|
|
14
|
+
Email: [contact@sophonz.ai]
|
|
15
|
+
Website: https://inobs.io
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @sophonz/node-sdk
|
|
2
|
+
|
|
3
|
+
Complete OpenTelemetry SDK for Node.js with automatic instrumentation, exception handling, and console capture.
|
|
4
|
+
|
|
5
|
+
Part of the Sophonz OpenTelemetry suite.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @sophonz/node-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @sophonz/node-sdk
|
|
13
|
+
# or
|
|
14
|
+
npm install @sophonz/node-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Programmatic Initialization
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { init, shutdown } from '@sophonz/node-sdk';
|
|
23
|
+
|
|
24
|
+
await init({
|
|
25
|
+
service: 'my-app',
|
|
26
|
+
apiKey: process.env.SOPHONZ_API_KEY,
|
|
27
|
+
consoleCapture: true,
|
|
28
|
+
experimentalExceptionCapture: true,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Your application code here
|
|
32
|
+
console.log('Application running');
|
|
33
|
+
|
|
34
|
+
// Graceful shutdown
|
|
35
|
+
await shutdown();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Command-line Instrumentation
|
|
39
|
+
|
|
40
|
+
Wrap your Node.js application with the preload binary:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
node -r @sophonz/node-sdk/build/bin/opentelemetry-instrument.js app.js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or use the provided CLI:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
opentelemetry-instrument app.js
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API
|
|
53
|
+
|
|
54
|
+
### `init(config?: Partial<SDKConfig>): Promise<void>`
|
|
55
|
+
|
|
56
|
+
Initialize the SDK with automatic instrumentation enabled.
|
|
57
|
+
|
|
58
|
+
### `initSDK(config: SDKConfig): void`
|
|
59
|
+
|
|
60
|
+
Initialize the SDK with explicit configuration control.
|
|
61
|
+
|
|
62
|
+
### `shutdown(): Promise<void>`
|
|
63
|
+
|
|
64
|
+
Gracefully shut down the SDK and flush all telemetry.
|
|
65
|
+
|
|
66
|
+
### `setTraceAttributes(attributes: Attributes): void`
|
|
67
|
+
|
|
68
|
+
Set global trace attributes on the mutable context.
|
|
69
|
+
|
|
70
|
+
### SDKConfig Options
|
|
71
|
+
|
|
72
|
+
- `service?: string` - Service name (default from env or auto-detected)
|
|
73
|
+
- `apiKey?: string` - API key for exporter authentication
|
|
74
|
+
- `consoleCapture?: boolean` - Instrument console API (default true)
|
|
75
|
+
- `experimentalExceptionCapture?: boolean` - Capture uncaught exceptions (default true)
|
|
76
|
+
- `sentryIntegrationEnabled?: boolean` - Enable Sentry integration (default true)
|
|
77
|
+
- `advancedNetworkCapture?: boolean` - Capture HTTP headers and bodies
|
|
78
|
+
- `disableTracing?: boolean` - Disable trace export
|
|
79
|
+
- `disableLogs?: boolean` - Disable log export
|
|
80
|
+
- `disableMetrics?: boolean` - Disable metric export
|
|
81
|
+
- `disableStartupLogs?: boolean` - Suppress initialization messages
|
|
82
|
+
- `stopOnTerminationSignals?: boolean` - Graceful shutdown on SIGTERM/SIGINT (default true)
|
|
83
|
+
- `detectResources?: boolean` - Auto-detect resource attributes (default true)
|
|
84
|
+
- `enableInternalProfiling?: boolean` - Profile instrumentation startup time
|
|
85
|
+
- `additionalInstrumentations?: InstrumentationBase[]` - Custom instrumentations
|
|
86
|
+
- `instrumentations?: InstrumentationConfigMap` - Override auto-instrumentation config
|
|
87
|
+
- `metricReader?: MetricReader` - Custom metric reader
|
|
88
|
+
|
|
89
|
+
## Included Instrumentations
|
|
90
|
+
|
|
91
|
+
- HTTP/HTTPS
|
|
92
|
+
- Console API
|
|
93
|
+
- Node.js exceptions
|
|
94
|
+
- Sentry integration
|
|
95
|
+
- Runtime metrics
|
|
96
|
+
- Express/Koa error handlers
|
|
97
|
+
|
|
98
|
+
## Peer dependencies
|
|
99
|
+
|
|
100
|
+
- `@opentelemetry/api`
|
|
101
|
+
- `@opentelemetry/sdk-node`
|
|
102
|
+
- `@opentelemetry/auto-instrumentations-node`
|
|
103
|
+
|
|
104
|
+
## Environment Variables
|
|
105
|
+
|
|
106
|
+
- `SOPHONZ_API_KEY` - API key for exporter
|
|
107
|
+
- `OTEL_SERVICE_NAME` - Service name
|
|
108
|
+
- `OTEL_LOG_LEVEL` - Diagnostics log level
|
|
109
|
+
- `SOPHONZ_STARTUP_LOGS` - Show/hide initialization messages
|
|
110
|
+
- Additional OTEL_* variables for OpenTelemetry configuration
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
See [LICENSE](./LICENSE) in this package.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
Part of [sophonz-js](https://github.com/sophonz-labs/sophonz-js).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry-instrument.d.ts","sourceRoot":"","sources":["../../bin/opentelemetry-instrument.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_1 = require("@opentelemetry/api");
|
|
6
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
+
const process_1 = tslib_1.__importDefault(require("process"));
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const realpath = (0, util_1.promisify)(fs_1.default.realpath);
|
|
10
|
+
const start = async () => {
|
|
11
|
+
await Promise.resolve().then(() => tslib_1.__importStar(require('../src/tracing')));
|
|
12
|
+
const givenEntryPath = process_1.default.argv[2];
|
|
13
|
+
const realEntryPath = await realpath(givenEntryPath);
|
|
14
|
+
process_1.default.argv[2] = realEntryPath;
|
|
15
|
+
process_1.default.argv.splice(1, 1);
|
|
16
|
+
require(realEntryPath);
|
|
17
|
+
};
|
|
18
|
+
start().catch((error) => {
|
|
19
|
+
api_1.diag.error('Error during OpenTelemetry instrumentation startup:', error);
|
|
20
|
+
process_1.default.exit(1);
|
|
21
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sophonz/node-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"homepage": "https://sophonz.com",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/sophonz-labs/sophonz-js.git"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@opentelemetry/api": "^1.9.1",
|
|
15
|
+
"@opentelemetry/api-logs": "^0.217.0",
|
|
16
|
+
"@opentelemetry/auto-instrumentations-node": "^0.75.0",
|
|
17
|
+
"@opentelemetry/core": "^2.7.1",
|
|
18
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.217.0",
|
|
19
|
+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.217.0",
|
|
20
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.217.0",
|
|
21
|
+
"@opentelemetry/instrumentation": "^0.217.0",
|
|
22
|
+
"@opentelemetry/instrumentation-http": "^0.217.0",
|
|
23
|
+
"@opentelemetry/instrumentation-runtime-node": "^0.30.0",
|
|
24
|
+
"@opentelemetry/resources": "^2.7.1",
|
|
25
|
+
"@opentelemetry/sdk-logs": "^0.217.0",
|
|
26
|
+
"@opentelemetry/sdk-metrics": "^2.7.1",
|
|
27
|
+
"@opentelemetry/sdk-node": "^0.217.0",
|
|
28
|
+
"@opentelemetry/sdk-trace-base": "~2.7.1",
|
|
29
|
+
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
30
|
+
"@sophonz/instrumentation-console": "*",
|
|
31
|
+
"@sophonz/instrumentation-node": "*",
|
|
32
|
+
"@sophonz/instrumentation-node-exception": "*",
|
|
33
|
+
"cli-spinners": "^3.4.0",
|
|
34
|
+
"json-stringify-safe": "^5.0.1",
|
|
35
|
+
"lodash.isobject": "^3.0.2",
|
|
36
|
+
"lodash.isplainobject": "^4.0.6",
|
|
37
|
+
"lodash.isstring": "^4.0.1",
|
|
38
|
+
"node-fetch": "^3.3.2",
|
|
39
|
+
"ora": "^9.4.0",
|
|
40
|
+
"pino-abstract-transport": "^3.0.0",
|
|
41
|
+
"semver": "^7.8.0",
|
|
42
|
+
"shimmer": "^1.2.1",
|
|
43
|
+
"tslib": "^2.8.1",
|
|
44
|
+
"winston": "^3.19.0",
|
|
45
|
+
"winston-transport": "^4.9.0"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"build/*"
|
|
49
|
+
],
|
|
50
|
+
"main": "build/src/index.js",
|
|
51
|
+
"bin": {
|
|
52
|
+
"opentelemetry-instrument": "build/bin/opentelemetry-instrument.js"
|
|
53
|
+
},
|
|
54
|
+
"types": "build/src/index.d.ts",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./build/src/index.d.ts",
|
|
58
|
+
"require": "./build/src/index.js",
|
|
59
|
+
"default": "./build/src/index.js"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContextManager, Context } from '@opentelemetry/api';
|
|
2
|
+
export declare abstract class AbstractAsyncHooksContextManager implements ContextManager {
|
|
3
|
+
abstract active(): Context;
|
|
4
|
+
abstract with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
5
|
+
abstract enable(): this;
|
|
6
|
+
abstract disable(): this;
|
|
7
|
+
bind<T>(context: Context, target: T): T;
|
|
8
|
+
private _bindFunction;
|
|
9
|
+
private _bindEventEmitter;
|
|
10
|
+
private _patchRemoveListener;
|
|
11
|
+
private _patchRemoveAllListeners;
|
|
12
|
+
private _patchAddListener;
|
|
13
|
+
private _createPatchMap;
|
|
14
|
+
private _getPatchMap;
|
|
15
|
+
private readonly _kOtListeners;
|
|
16
|
+
private _wrapped;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=AbstractAsyncHooksContextManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractAsyncHooksContextManager.d.ts","sourceRoot":"","sources":["../../src/AbstractAsyncHooksContextManager.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAsB7D,8BAAsB,gCACpB,YAAW,cAAc;IAEzB,QAAQ,CAAC,MAAM,IAAI,OAAO;IAE1B,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EACxE,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,CAAC,EACL,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,GAAG,IAAI,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC;IAEhB,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,QAAQ,CAAC,OAAO,IAAI,IAAI;IAQxB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC;IAWvC,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,wBAAwB;IAsBhC,OAAO,CAAC,iBAAiB;IA2CzB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;IACvD,OAAO,CAAC,QAAQ,CAAS;CAC1B"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAsyncHooksContextManager = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const ADD_LISTENER_METHODS = [
|
|
6
|
+
'addListener',
|
|
7
|
+
'on',
|
|
8
|
+
'once',
|
|
9
|
+
'prependListener',
|
|
10
|
+
'prependOnceListener',
|
|
11
|
+
];
|
|
12
|
+
class AbstractAsyncHooksContextManager {
|
|
13
|
+
constructor() {
|
|
14
|
+
this._kOtListeners = Symbol('OtListeners');
|
|
15
|
+
this._wrapped = false;
|
|
16
|
+
}
|
|
17
|
+
bind(context, target) {
|
|
18
|
+
if (target instanceof events_1.EventEmitter) {
|
|
19
|
+
return this._bindEventEmitter(context, target);
|
|
20
|
+
}
|
|
21
|
+
if (typeof target === 'function') {
|
|
22
|
+
return this._bindFunction(context, target);
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
_bindFunction(context, target) {
|
|
27
|
+
const manager = this;
|
|
28
|
+
const contextWrapper = function (...args) {
|
|
29
|
+
return manager.with(context, () => target.apply(this, args));
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(contextWrapper, 'length', {
|
|
32
|
+
enumerable: false,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: false,
|
|
35
|
+
value: target.length,
|
|
36
|
+
});
|
|
37
|
+
return contextWrapper;
|
|
38
|
+
}
|
|
39
|
+
_bindEventEmitter(context, ee) {
|
|
40
|
+
const map = this._getPatchMap(ee);
|
|
41
|
+
if (map !== undefined)
|
|
42
|
+
return ee;
|
|
43
|
+
this._createPatchMap(ee);
|
|
44
|
+
ADD_LISTENER_METHODS.forEach((methodName) => {
|
|
45
|
+
if (ee[methodName] === undefined)
|
|
46
|
+
return;
|
|
47
|
+
ee[methodName] = this._patchAddListener(ee, ee[methodName], context);
|
|
48
|
+
});
|
|
49
|
+
if (typeof ee.removeListener === 'function') {
|
|
50
|
+
ee.removeListener = this._patchRemoveListener(ee, ee.removeListener);
|
|
51
|
+
}
|
|
52
|
+
if (typeof ee.off === 'function') {
|
|
53
|
+
ee.off = this._patchRemoveListener(ee, ee.off);
|
|
54
|
+
}
|
|
55
|
+
if (typeof ee.removeAllListeners === 'function') {
|
|
56
|
+
ee.removeAllListeners = this._patchRemoveAllListeners(ee, ee.removeAllListeners);
|
|
57
|
+
}
|
|
58
|
+
return ee;
|
|
59
|
+
}
|
|
60
|
+
_patchRemoveListener(ee, original) {
|
|
61
|
+
const contextManager = this;
|
|
62
|
+
return function (event, listener) {
|
|
63
|
+
var _a;
|
|
64
|
+
const events = (_a = contextManager._getPatchMap(ee)) === null || _a === void 0 ? void 0 : _a[event];
|
|
65
|
+
if (events === undefined) {
|
|
66
|
+
return original.call(this, event, listener);
|
|
67
|
+
}
|
|
68
|
+
const patchedListener = events.get(listener);
|
|
69
|
+
return original.call(this, event, patchedListener || listener);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
_patchRemoveAllListeners(ee, original) {
|
|
73
|
+
const contextManager = this;
|
|
74
|
+
return function (event) {
|
|
75
|
+
const map = contextManager._getPatchMap(ee);
|
|
76
|
+
if (map !== undefined) {
|
|
77
|
+
if (arguments.length === 0) {
|
|
78
|
+
contextManager._createPatchMap(ee);
|
|
79
|
+
}
|
|
80
|
+
else if (map[event] !== undefined) {
|
|
81
|
+
delete map[event];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return original.apply(this, arguments);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
_patchAddListener(ee, original, context) {
|
|
88
|
+
const contextManager = this;
|
|
89
|
+
return function (event, listener) {
|
|
90
|
+
if (contextManager._wrapped) {
|
|
91
|
+
return original.call(this, event, listener);
|
|
92
|
+
}
|
|
93
|
+
let map = contextManager._getPatchMap(ee);
|
|
94
|
+
if (map === undefined) {
|
|
95
|
+
map = contextManager._createPatchMap(ee);
|
|
96
|
+
}
|
|
97
|
+
let listeners = map[event];
|
|
98
|
+
if (listeners === undefined) {
|
|
99
|
+
listeners = new WeakMap();
|
|
100
|
+
map[event] = listeners;
|
|
101
|
+
}
|
|
102
|
+
const patchedListener = contextManager.bind(context, listener);
|
|
103
|
+
listeners.set(listener, patchedListener);
|
|
104
|
+
contextManager._wrapped = true;
|
|
105
|
+
try {
|
|
106
|
+
return original.call(this, event, patchedListener);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
contextManager._wrapped = false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
_createPatchMap(ee) {
|
|
114
|
+
const map = Object.create(null);
|
|
115
|
+
ee[this._kOtListeners] = map;
|
|
116
|
+
return map;
|
|
117
|
+
}
|
|
118
|
+
_getPatchMap(ee) {
|
|
119
|
+
return ee[this._kOtListeners];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.AbstractAsyncHooksContextManager = AbstractAsyncHooksContextManager;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context } from '@opentelemetry/api';
|
|
2
|
+
import { AbstractAsyncHooksContextManager } from './AbstractAsyncHooksContextManager';
|
|
3
|
+
export declare class MutableAsyncLocalStorageContextManager extends AbstractAsyncHooksContextManager {
|
|
4
|
+
private _asyncLocalStorage;
|
|
5
|
+
constructor();
|
|
6
|
+
active(): Context;
|
|
7
|
+
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
8
|
+
getMutableContext(): {
|
|
9
|
+
traceAttributes: Map<string, any>;
|
|
10
|
+
};
|
|
11
|
+
enable(): this;
|
|
12
|
+
disable(): this;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MutableAsyncLocalStorageContextManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutableAsyncLocalStorageContextManager.d.ts","sourceRoot":"","sources":["../../src/MutableAsyncLocalStorageContextManager.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,OAAO,EAAgB,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAStF,qBAAa,sCAAuC,SAAQ,gCAAgC;IAC1F,OAAO,CAAC,kBAAkB,CAAyC;;IAOnE,MAAM,IAAI,OAAO;IAIjB,IAAI,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAC/D,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,CAAC,EACL,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,GAAG,IAAI,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC;IAchB,iBAAiB;yBAnCE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;;IAuCnC,MAAM,IAAI,IAAI;IAId,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MutableAsyncLocalStorageContextManager = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const async_hooks_1 = require("async_hooks");
|
|
6
|
+
const AbstractAsyncHooksContextManager_1 = require("./AbstractAsyncHooksContextManager");
|
|
7
|
+
class MutableAsyncLocalStorageContextManager extends AbstractAsyncHooksContextManager_1.AbstractAsyncHooksContextManager {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this._asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
11
|
+
}
|
|
12
|
+
active() {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return (_b = (_a = this._asyncLocalStorage.getStore()) === null || _a === void 0 ? void 0 : _a.context) !== null && _b !== void 0 ? _b : api_1.ROOT_CONTEXT;
|
|
15
|
+
}
|
|
16
|
+
with(context, fn, thisArg, ...args) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const mutableContext = (_b = (_a = this._asyncLocalStorage.getStore()) === null || _a === void 0 ? void 0 : _a.mutableContext) !== null && _b !== void 0 ? _b : {
|
|
19
|
+
traceAttributes: new Map(),
|
|
20
|
+
};
|
|
21
|
+
const cb = thisArg == null ? fn : fn.bind(thisArg);
|
|
22
|
+
return this._asyncLocalStorage.run({ context, mutableContext }, cb, ...args);
|
|
23
|
+
}
|
|
24
|
+
getMutableContext() {
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = this._asyncLocalStorage.getStore()) === null || _a === void 0 ? void 0 : _a.mutableContext;
|
|
27
|
+
}
|
|
28
|
+
enable() {
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
disable() {
|
|
32
|
+
this._asyncLocalStorage.disable();
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.MutableAsyncLocalStorageContextManager = MutableAsyncLocalStorageContextManager;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const DEFAULT_EXPORTER_BATCH_SIZE: number;
|
|
2
|
+
export declare const DEFAULT_EXPORTER_TIMEOUT_MS: number;
|
|
3
|
+
export declare const DEFAULT_MAX_QUEUE_SIZE: number;
|
|
4
|
+
export declare const DEFAULT_OTEL_TRACES_EXPORTER: string;
|
|
5
|
+
export declare const DEFAULT_OTEL_TRACES_EXPORTER_URL: string;
|
|
6
|
+
export declare const DEFAULT_OTEL_TRACES_SAMPLER: string;
|
|
7
|
+
export declare const DEFAULT_OTEL_TRACES_SAMPLER_ARG: string;
|
|
8
|
+
export declare const DEFAULT_OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: number;
|
|
9
|
+
export declare const DEFAULT_SEND_INTERVAL_MS: number;
|
|
10
|
+
export declare const DEFAULT_OTEL_LOGS_EXPORTER: string;
|
|
11
|
+
export declare const DEFAULT_OTEL_LOGS_EXPORTER_URL: string;
|
|
12
|
+
export declare const DEFAULT_OTEL_METRICS_EXPORTER: string;
|
|
13
|
+
export declare const DEFAULT_OTEL_METRICS_EXPORTER_URL: string;
|
|
14
|
+
export declare const DEFAULT_OTEL_METRIC_EXPORT_INTERVAL: number;
|
|
15
|
+
export declare const DEFAULT_OTEL_METRIC_EXPORT_TIMEOUT: number;
|
|
16
|
+
export declare const DEFAULT_SERVICE_NAME: () => string;
|
|
17
|
+
export declare const DEFAULT_OTEL_LOG_LEVEL: string;
|
|
18
|
+
export declare const DEFAULT_SOPHONZ_API_KEY: () => string;
|
|
19
|
+
export declare const DEFAULT_SOPHONZ_NODE_BETA_MODE: () => boolean;
|
|
20
|
+
export declare const DEFAULT_SOPHONZ_NODE_CONSOLE_CAPTURE: boolean;
|
|
21
|
+
export declare const DEFAULT_SOPHONZ_NODE_ADVANCED_NETWORK_CAPTURE: boolean;
|
|
22
|
+
export declare const DEFAULT_SOPHONZ_NODE_STOP_ON_TERMINATION_SIGNALS: boolean;
|
|
23
|
+
export declare const DEFAULT_SOPHONZ_NODE_EXPERIMENTAL_EXCEPTION_CAPTURE: boolean;
|
|
24
|
+
export declare const DEFAULT_SOPHONZ_NODE_SENTRY_INTEGRATION_ENABLED: boolean;
|
|
25
|
+
export declare const DEFAULT_SOPHONZ_NODE_ENABLE_INTERNAL_PROFILING: boolean;
|
|
26
|
+
export declare const DEFAULT_SOPHONZ_STARTUP_LOGS: boolean;
|
|
27
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,2BAA2B,QACoB,CAAC;AAC7D,eAAO,MAAM,2BAA2B,QACe,CAAC;AACxD,eAAO,MAAM,sBAAsB,QACmB,CAAC;AACvD,eAAO,MAAM,4BAA4B,QAA2C,CAAC;AACrF,eAAO,MAAM,gCAAgC,QAEiD,CAAC;AAC/F,eAAO,MAAM,2BAA2B,QAC4B,CAAC;AACrE,eAAO,MAAM,+BAA+B,QACQ,CAAC;AACrD,eAAO,MAAM,yCAAyC,QACU,CAAC;AACjE,eAAO,MAAM,wBAAwB,QACiB,CAAC;AACvD,eAAO,MAAM,0BAA0B,QAAyC,CAAC;AACjF,eAAO,MAAM,8BAA8B,QAIC,CAAC;AAC7C,eAAO,MAAM,6BAA6B,QAA4C,CAAC;AACvF,eAAO,MAAM,iCAAiC,QAIC,CAAC;AAChD,eAAO,MAAM,mCAAmC,QACU,CAAC;AAC3D,eAAO,MAAM,kCAAkC,QAA0D,CAAC;AAC1G,eAAO,MAAM,oBAAoB,cAC8B,CAAC;AAChE,eAAO,MAAM,sBAAsB,QAAqC,CAAC;AAEzE,eAAO,MAAM,uBAAuB,cAA4C,CAAC;AACjF,eAAO,MAAM,8BAA8B,eACW,CAAC;AACvD,eAAO,MAAM,oCAAoC,SACU,CAAC;AAC5D,eAAO,MAAM,6CAA6C,SACW,CAAC;AACtE,eAAO,MAAM,gDAAgD,SACU,CAAC;AACxE,eAAO,MAAM,mDAAmD,SACW,CAAC;AAC5E,eAAO,MAAM,+CAA+C,SACW,CAAC;AACxE,eAAO,MAAM,8CAA8C,SACW,CAAC;AACvE,eAAO,MAAM,4BAA4B,SACU,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DEFAULT_SOPHONZ_STARTUP_LOGS = exports.DEFAULT_SOPHONZ_NODE_ENABLE_INTERNAL_PROFILING = exports.DEFAULT_SOPHONZ_NODE_SENTRY_INTEGRATION_ENABLED = exports.DEFAULT_SOPHONZ_NODE_EXPERIMENTAL_EXCEPTION_CAPTURE = exports.DEFAULT_SOPHONZ_NODE_STOP_ON_TERMINATION_SIGNALS = exports.DEFAULT_SOPHONZ_NODE_ADVANCED_NETWORK_CAPTURE = exports.DEFAULT_SOPHONZ_NODE_CONSOLE_CAPTURE = exports.DEFAULT_SOPHONZ_NODE_BETA_MODE = exports.DEFAULT_SOPHONZ_API_KEY = exports.DEFAULT_OTEL_LOG_LEVEL = exports.DEFAULT_SERVICE_NAME = exports.DEFAULT_OTEL_METRIC_EXPORT_TIMEOUT = exports.DEFAULT_OTEL_METRIC_EXPORT_INTERVAL = exports.DEFAULT_OTEL_METRICS_EXPORTER_URL = exports.DEFAULT_OTEL_METRICS_EXPORTER = exports.DEFAULT_OTEL_LOGS_EXPORTER_URL = exports.DEFAULT_OTEL_LOGS_EXPORTER = exports.DEFAULT_SEND_INTERVAL_MS = exports.DEFAULT_OTEL_EXPORTER_OTLP_TRACES_TIMEOUT = exports.DEFAULT_OTEL_TRACES_SAMPLER_ARG = exports.DEFAULT_OTEL_TRACES_SAMPLER = exports.DEFAULT_OTEL_TRACES_EXPORTER_URL = exports.DEFAULT_OTEL_TRACES_EXPORTER = exports.DEFAULT_MAX_QUEUE_SIZE = exports.DEFAULT_EXPORTER_TIMEOUT_MS = exports.DEFAULT_EXPORTER_BATCH_SIZE = void 0;
|
|
5
|
+
const core_1 = require("@opentelemetry/core");
|
|
6
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const env = process.env;
|
|
9
|
+
exports.DEFAULT_EXPORTER_BATCH_SIZE = (_a = (0, core_1.getNumberFromEnv)("OTEL_BLRP_MAX_EXPORT_BATCH_SIZE")) !== null && _a !== void 0 ? _a : 512;
|
|
10
|
+
exports.DEFAULT_EXPORTER_TIMEOUT_MS = (_b = (0, core_1.getNumberFromEnv)("OTEL_BLRP_EXPORT_TIMEOUT")) !== null && _b !== void 0 ? _b : 30000;
|
|
11
|
+
exports.DEFAULT_MAX_QUEUE_SIZE = (_c = (0, core_1.getNumberFromEnv)("OTEL_BLRP_MAX_QUEUE_SIZE")) !== null && _c !== void 0 ? _c : 2048;
|
|
12
|
+
exports.DEFAULT_OTEL_TRACES_EXPORTER = (0, core_1.getStringFromEnv)("OTEL_TRACES_EXPORTER");
|
|
13
|
+
exports.DEFAULT_OTEL_TRACES_EXPORTER_URL = (_d = (0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT")) !== null && _d !== void 0 ? _d : ((_e = (0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_ENDPOINT")) !== null && _e !== void 0 ? _e : 'https://in-otel.sophonz.com/v1/traces');
|
|
14
|
+
exports.DEFAULT_OTEL_TRACES_SAMPLER = (_f = (0, core_1.getStringFromEnv)("OTEL_TRACES_SAMPLER")) !== null && _f !== void 0 ? _f : 'parentbased_always_on';
|
|
15
|
+
exports.DEFAULT_OTEL_TRACES_SAMPLER_ARG = (_g = (0, core_1.getStringFromEnv)("OTEL_TRACES_SAMPLER_ARG")) !== null && _g !== void 0 ? _g : '1';
|
|
16
|
+
exports.DEFAULT_OTEL_EXPORTER_OTLP_TRACES_TIMEOUT = (_h = (0, core_1.getNumberFromEnv)("OTEL_EXPORTER_OTLP_TRACES_TIMEOUT")) !== null && _h !== void 0 ? _h : 60000;
|
|
17
|
+
exports.DEFAULT_SEND_INTERVAL_MS = (_j = (0, core_1.getNumberFromEnv)("OTEL_BLRP_SCHEDULE_DELAY")) !== null && _j !== void 0 ? _j : 2000;
|
|
18
|
+
exports.DEFAULT_OTEL_LOGS_EXPORTER = (0, core_1.getStringFromEnv)("OTEL_LOGS_EXPORTER");
|
|
19
|
+
exports.DEFAULT_OTEL_LOGS_EXPORTER_URL = (_k = (0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT")) !== null && _k !== void 0 ? _k : ((0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_ENDPOINT")
|
|
20
|
+
? `${(0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_ENDPOINT")}/v1/logs`
|
|
21
|
+
: 'https://in-otel.sophonz.com/v1/logs');
|
|
22
|
+
exports.DEFAULT_OTEL_METRICS_EXPORTER = (0, core_1.getStringFromEnv)("OTEL_METRICS_EXPORTER");
|
|
23
|
+
exports.DEFAULT_OTEL_METRICS_EXPORTER_URL = (_l = (0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT")) !== null && _l !== void 0 ? _l : ((0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_ENDPOINT")
|
|
24
|
+
? `${(0, core_1.getStringFromEnv)("OTEL_EXPORTER_OTLP_ENDPOINT")}/v1/metrics`
|
|
25
|
+
: 'https://in-otel.sophonz.com/v1/metrics');
|
|
26
|
+
exports.DEFAULT_OTEL_METRIC_EXPORT_INTERVAL = (_m = (0, core_1.getNumberFromEnv)("OTEL_METRIC_EXPORT_INTERVAL")) !== null && _m !== void 0 ? _m : 60000;
|
|
27
|
+
exports.DEFAULT_OTEL_METRIC_EXPORT_TIMEOUT = (_o = (0, core_1.getNumberFromEnv)("OTEL_METRIC_EXPORT_TIMEOUT")) !== null && _o !== void 0 ? _o : 30000;
|
|
28
|
+
const DEFAULT_SERVICE_NAME = () => { var _a; return (_a = (0, core_1.getStringFromEnv)("OTEL_SERVICE_NAME")) !== null && _a !== void 0 ? _a : (0, resources_1.defaultServiceName)(); };
|
|
29
|
+
exports.DEFAULT_SERVICE_NAME = DEFAULT_SERVICE_NAME;
|
|
30
|
+
exports.DEFAULT_OTEL_LOG_LEVEL = (0, core_1.getStringFromEnv)("OTEL_LOG_LEVEL");
|
|
31
|
+
const DEFAULT_SOPHONZ_API_KEY = () => (0, core_1.getStringFromEnv)("SOPHONZ_API_KEY");
|
|
32
|
+
exports.DEFAULT_SOPHONZ_API_KEY = DEFAULT_SOPHONZ_API_KEY;
|
|
33
|
+
const DEFAULT_SOPHONZ_NODE_BETA_MODE = () => { var _a; return (_a = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_BETA_MODE)) !== null && _a !== void 0 ? _a : false; };
|
|
34
|
+
exports.DEFAULT_SOPHONZ_NODE_BETA_MODE = DEFAULT_SOPHONZ_NODE_BETA_MODE;
|
|
35
|
+
exports.DEFAULT_SOPHONZ_NODE_CONSOLE_CAPTURE = (_p = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_CONSOLE_CAPTURE)) !== null && _p !== void 0 ? _p : true;
|
|
36
|
+
exports.DEFAULT_SOPHONZ_NODE_ADVANCED_NETWORK_CAPTURE = (_q = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_ADVANCED_NETWORK_CAPTURE)) !== null && _q !== void 0 ? _q : false;
|
|
37
|
+
exports.DEFAULT_SOPHONZ_NODE_STOP_ON_TERMINATION_SIGNALS = (_r = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_STOP_ON_TERMINATION_SIGNALS)) !== null && _r !== void 0 ? _r : true;
|
|
38
|
+
exports.DEFAULT_SOPHONZ_NODE_EXPERIMENTAL_EXCEPTION_CAPTURE = (_s = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_EXPERIMENTAL_EXCEPTION_CAPTURE)) !== null && _s !== void 0 ? _s : false;
|
|
39
|
+
exports.DEFAULT_SOPHONZ_NODE_SENTRY_INTEGRATION_ENABLED = (_t = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_SENTRY_INTEGRATION_ENABLED)) !== null && _t !== void 0 ? _t : false;
|
|
40
|
+
exports.DEFAULT_SOPHONZ_NODE_ENABLE_INTERNAL_PROFILING = (_u = (0, utils_1.stringToBoolean)(env.SOPHONZ_NODE_ENABLE_INTERNAL_PROFILING)) !== null && _u !== void 0 ? _u : false;
|
|
41
|
+
exports.DEFAULT_SOPHONZ_STARTUP_LOGS = (_v = (0, utils_1.stringToBoolean)(env.SOPHONZ_STARTUP_LOGS)) !== null && _v !== void 0 ? _v : true;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp.d.ts","sourceRoot":"","sources":["../../src/gcp.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE5C,eAAO,MAAM,oCAAoC,GAC/C,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EACtC,YAAW,SAAc,MAGX,UAAK,kBA8DpB,CAAC"}
|
package/build/src/gcp.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerGCPCloudFunctionEventHandler = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
6
|
+
const package_json_1 = require("../package.json");
|
|
7
|
+
const otel_1 = require("./otel");
|
|
8
|
+
const registerGCPCloudFunctionEventHandler = (handler, sdkConfig = {}) => {
|
|
9
|
+
(0, otel_1.initSDK)(sdkConfig);
|
|
10
|
+
return async (event) => {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
const tracer = api_1.trace.getTracer(package_json_1.name, package_json_1.version);
|
|
13
|
+
let parentSpanContext;
|
|
14
|
+
let attributes;
|
|
15
|
+
let spanName = 'cloudFunctionEventHandler';
|
|
16
|
+
if (event.type === 'google.cloud.pubsub.topic.v1.messagePublished' &&
|
|
17
|
+
((_c = (_b = (_a = event.data) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.attributes) === null || _c === void 0 ? void 0 : _c['googclient_OpenTelemetrySpanContext'])) {
|
|
18
|
+
if (event.data.subscription) {
|
|
19
|
+
spanName = `${event.data.subscription} process`;
|
|
20
|
+
}
|
|
21
|
+
const message = event.data.message;
|
|
22
|
+
const parentSpanValue = message.attributes['googclient_OpenTelemetrySpanContext'];
|
|
23
|
+
parentSpanContext = parentSpanValue
|
|
24
|
+
? JSON.parse(parentSpanValue)
|
|
25
|
+
: undefined;
|
|
26
|
+
attributes = {
|
|
27
|
+
ackId: message.ackId,
|
|
28
|
+
deliveryAttempt: message.deliveryAttempt,
|
|
29
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_SYSTEM]: 'pubsub',
|
|
30
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_OPERATION]: 'process',
|
|
31
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION]: event.data.subscription,
|
|
32
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION_KIND]: 'topic',
|
|
33
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_MESSAGE_ID]: message.id,
|
|
34
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_PROTOCOL]: 'pubsub',
|
|
35
|
+
[semantic_conventions_1.SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES]: message.data.length,
|
|
36
|
+
'messaging.pubsub.received_at': message.received,
|
|
37
|
+
'messaging.pubsub.acknowlege_id': message.ackId,
|
|
38
|
+
'messaging.pubsub.delivery_attempt': message.deliveryAttempt,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
await tracer.startActiveSpan(spanName, {
|
|
42
|
+
kind: api_1.SpanKind.CONSUMER,
|
|
43
|
+
...(attributes ? { attributes } : {}),
|
|
44
|
+
}, parentSpanContext
|
|
45
|
+
? api_1.trace.setSpanContext(api_1.context.active(), parentSpanContext)
|
|
46
|
+
: api_1.context.active(), async (span) => {
|
|
47
|
+
try {
|
|
48
|
+
await handler(event);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
span.recordException(e);
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
span.end();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.registerGCPCloudFunctionEventHandler = registerGCPCloudFunctionEventHandler;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './gcp';
|
|
2
|
+
export * from './logger';
|
|
3
|
+
export * from './otel';
|
|
4
|
+
export { recordException, setupExpressErrorHandler, setupKoaErrorHandler, } from '@sophonz/instrumentation-node-exception';
|
|
5
|
+
export type { MutableAsyncLocalStorageContextManager } from "./MutableAsyncLocalStorageContextManager";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,yCAAyC,CAAC;AAEjD,YAAY,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupKoaErrorHandler = exports.setupExpressErrorHandler = exports.recordException = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./gcp"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./logger"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./otel"), exports);
|
|
8
|
+
var instrumentation_node_exception_1 = require("@sophonz/instrumentation-node-exception");
|
|
9
|
+
Object.defineProperty(exports, "recordException", { enumerable: true, get: function () { return instrumentation_node_exception_1.recordException; } });
|
|
10
|
+
Object.defineProperty(exports, "setupExpressErrorHandler", { enumerable: true, get: function () { return instrumentation_node_exception_1.setupExpressErrorHandler; } });
|
|
11
|
+
Object.defineProperty(exports, "setupKoaErrorHandler", { enumerable: true, get: function () { return instrumentation_node_exception_1.setupKoaErrorHandler; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InstrumentationBase, InstrumentationConfig, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
+
import { MutableAsyncLocalStorageContextManager } from '../MutableAsyncLocalStorageContextManager';
|
|
3
|
+
import { LoggerOptions } from '../otel-logger';
|
|
4
|
+
export declare const _parseConsoleArgs: (args: any[]) => any;
|
|
5
|
+
export interface SophonzConsoleInstrumentationConfig extends InstrumentationConfig {
|
|
6
|
+
betaMode: boolean;
|
|
7
|
+
loggerOptions: LoggerOptions;
|
|
8
|
+
contextManager?: MutableAsyncLocalStorageContextManager;
|
|
9
|
+
}
|
|
10
|
+
export default class SophonzConsoleInstrumentation extends InstrumentationBase {
|
|
11
|
+
private readonly _hdxLogger;
|
|
12
|
+
private readonly _contextManager;
|
|
13
|
+
private _patchConsole;
|
|
14
|
+
private readonly _consoleLogHandler;
|
|
15
|
+
private readonly _consoleInfoHandler;
|
|
16
|
+
private readonly _consoleWarnHandler;
|
|
17
|
+
private readonly _consoleErrorHandler;
|
|
18
|
+
private readonly _consoleDebugHandler;
|
|
19
|
+
private _onPatch;
|
|
20
|
+
private _onUnPatch;
|
|
21
|
+
constructor(config: SophonzConsoleInstrumentationConfig);
|
|
22
|
+
init(): InstrumentationNodeModuleDefinition[];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../src/instrumentations/console.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,mCAAmC,EACpC,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,sCAAsC,EAAE,MAAM,2CAA2C,CAAC;AACnG,OAAO,EAAU,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMvD,eAAO,MAAM,iBAAiB,GAAI,MAAM,GAAG,EAAE,QA8B5C,CAAC;AAEF,MAAM,WAAW,mCACf,SAAQ,qBAAqB;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,CAAC,EAAE,sCAAsC,CAAC;CACzD;AAED,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,mBAAmB;IAC5E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAElB;IAEd,OAAO,CAAC,aAAa;IAmDrB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAMjC;IAEF,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAMlC;IAEF,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAMlC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAMnC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAMnC;IAEF,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,UAAU;gBAQN,MAAM,EAAE,mCAAmC;IAMvD,IAAI;CAgBL"}
|