@devopsplaybook.io/otel-utils 1.0.5 → 1.0.7-beta.6.01832d5

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.
@@ -0,0 +1,117 @@
1
+ name: Main Build
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ test-and-build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Setup Node.js
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: "18"
20
+ cache: "npm"
21
+
22
+ - name: Install dependencies
23
+ run: npm ci
24
+
25
+ - name: Run linting
26
+ run: npm run lint || echo "No lint script found, skipping"
27
+
28
+ - name: Run tests
29
+ run: npm test || echo "No test script found, skipping"
30
+
31
+ - name: Build package
32
+ run: npm run build
33
+
34
+ publish-release:
35
+ runs-on: ubuntu-latest
36
+ needs: test-and-build
37
+
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ with:
41
+ fetch-depth: 0 # Need full history for version comparison
42
+
43
+ - name: Setup Node.js
44
+ uses: actions/setup-node@v4
45
+ with:
46
+ node-version: "18"
47
+ cache: "npm"
48
+ registry-url: "https://registry.npmjs.org"
49
+
50
+ - name: Install dependencies
51
+ run: npm ci
52
+
53
+ - name: Build package
54
+ run: npm run build
55
+
56
+ - name: Check if version changed
57
+ id: version-check
58
+ run: |
59
+ # Get current version from package.json
60
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
61
+ echo "current-version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
62
+
63
+ # Check if this version exists on npm
64
+ if npm view @devopsplaybook.io/otel-utils@${CURRENT_VERSION} version &> /dev/null; then
65
+ echo "version-exists=true" >> $GITHUB_OUTPUT
66
+ echo "Version ${CURRENT_VERSION} already exists on npm"
67
+ else
68
+ echo "version-exists=false" >> $GITHUB_OUTPUT
69
+ echo "Version ${CURRENT_VERSION} is new, will publish"
70
+ fi
71
+
72
+ - name: Publish release package
73
+ if: steps.version-check.outputs.version-exists == 'false'
74
+ run: |
75
+ echo "Publishing version ${{ steps.version-check.outputs.current-version }}"
76
+ npm publish
77
+ env:
78
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
79
+
80
+ - name: Create Git Tag
81
+ if: steps.version-check.outputs.version-exists == 'false'
82
+ run: |
83
+ git config --local user.email "action@github.com"
84
+ git config --local user.name "GitHub Action"
85
+ git tag -a v${{ steps.version-check.outputs.current-version }} -m "Release v${{ steps.version-check.outputs.current-version }}"
86
+ git push origin v${{ steps.version-check.outputs.current-version }}
87
+
88
+ - name: Create GitHub Release
89
+ if: steps.version-check.outputs.version-exists == 'false'
90
+ uses: actions/create-release@v1
91
+ env:
92
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93
+ with:
94
+ tag_name: v${{ steps.version-check.outputs.current-version }}
95
+ release_name: Release v${{ steps.version-check.outputs.current-version }}
96
+ draft: false
97
+ prerelease: false
98
+ body: |
99
+ ## Release v${{ steps.version-check.outputs.current-version }}
100
+
101
+ **Package**: `@devopsplaybook.io/otel-utils@${{ steps.version-check.outputs.current-version }}`
102
+
103
+ Install with:
104
+ ```bash
105
+ npm install @devopsplaybook.io/otel-utils@${{ steps.version-check.outputs.current-version }}
106
+ # or for latest
107
+ npm install @devopsplaybook.io/otel-utils
108
+ ```
109
+
110
+ ### Changes
111
+ This release includes all changes merged since the previous version.
112
+
113
+ - name: Skip publish - version exists
114
+ if: steps.version-check.outputs.version-exists == 'true'
115
+ run: |
116
+ echo "⚠️ Version ${{ steps.version-check.outputs.current-version }} already exists on npm."
117
+ echo "To publish a new version, update the version in package.json first."
@@ -0,0 +1,98 @@
1
+ name: PR Check
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ["main"]
6
+
7
+ workflow_dispatch:
8
+
9
+ concurrency:
10
+ group: pr-${{ github.event.pull_request.number || github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test-and-build:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Setup Node.js
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: "18"
24
+ cache: "npm"
25
+
26
+ - name: Install dependencies
27
+ run: npm ci
28
+
29
+ - name: Run linting
30
+ run: npm run lint || echo "No lint script found, skipping"
31
+
32
+ - name: Run tests
33
+ run: npm test || echo "No test script found, skipping"
34
+
35
+ - name: Build package
36
+ run: npm run build
37
+
38
+ publish-beta:
39
+ runs-on: ubuntu-latest
40
+ needs: test-and-build
41
+ if: github.event_name == 'pull_request'
42
+
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+
46
+ - name: Setup Node.js
47
+ uses: actions/setup-node@v4
48
+ with:
49
+ node-version: "18"
50
+ cache: "npm"
51
+ registry-url: "https://registry.npmjs.org"
52
+
53
+ - name: Install dependencies
54
+ run: npm ci
55
+
56
+ - name: Build package
57
+ run: npm run build
58
+
59
+ - name: Generate beta version
60
+ id: beta-version
61
+ run: |
62
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
63
+ PR_NUMBER=${{ github.event.pull_request.number }}
64
+ COMMIT_SHA=${GITHUB_SHA:0:7}
65
+ BETA_VERSION="${CURRENT_VERSION}-beta.${PR_NUMBER}.${COMMIT_SHA}"
66
+ echo "version=${BETA_VERSION}" >> $GITHUB_OUTPUT
67
+ echo "Beta version will be: ${BETA_VERSION}"
68
+
69
+ - name: Update package.json with beta version
70
+ run: |
71
+ npm version ${{ steps.beta-version.outputs.version }} --no-git-tag-version
72
+
73
+ - name: Publish beta package
74
+ run: npm publish --tag beta
75
+ env:
76
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
77
+
78
+ - name: Comment PR with beta version info
79
+ uses: actions/github-script@v7
80
+ with:
81
+ script: |
82
+ github.rest.issues.createComment({
83
+ issue_number: context.issue.number,
84
+ owner: context.repo.owner,
85
+ repo: context.repo.repo,
86
+ body: `🚀 **Beta version published!**
87
+
88
+ **Package**: \`@devopsplaybook.io/otel-utils@${{ steps.beta-version.outputs.version }}\`
89
+
90
+ Install with:
91
+ \`\`\`bash
92
+ npm install @devopsplaybook.io/otel-utils@${{ steps.beta-version.outputs.version }}
93
+ # or
94
+ npm install @devopsplaybook.io/otel-utils@beta
95
+ \`\`\`
96
+
97
+ This beta version will be available for testing until the PR is merged.`
98
+ })
@@ -0,0 +1,6 @@
1
+ export * from "./src/models/ConfigOTelInterface";
2
+ export * from "./src/models/StandardLoggerInterface";
3
+ export * from "./src/ModuleLogger";
4
+ export * from "./src/StandardLogger";
5
+ export * from "./src/StandardMeter";
6
+ export * from "./src/StandardTracer";
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src/models/ConfigOTelInterface"), exports);
18
+ __exportStar(require("./src/models/StandardLoggerInterface"), exports);
19
+ __exportStar(require("./src/ModuleLogger"), exports);
20
+ __exportStar(require("./src/StandardLogger"), exports);
21
+ __exportStar(require("./src/StandardMeter"), exports);
22
+ __exportStar(require("./src/StandardTracer"), exports);
@@ -0,0 +1,11 @@
1
+ import { StandardLoggerInterface } from "./models/StandardLoggerInterface";
2
+ import { Span } from "@opentelemetry/sdk-trace-base";
3
+ export declare class ModuleLogger {
4
+ private module;
5
+ private standardLogger?;
6
+ constructor(module: string, standardLogger: StandardLoggerInterface);
7
+ info(message: string, context?: Span): void;
8
+ warn(message: string, context?: Span): void;
9
+ error(message: string, error?: Error, context?: Span): void;
10
+ private display;
11
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModuleLogger = void 0;
4
+ const api_logs_1 = require("@opentelemetry/api-logs");
5
+ class ModuleLogger {
6
+ constructor(module, standardLogger) {
7
+ this.module = module;
8
+ this.standardLogger = standardLogger;
9
+ }
10
+ info(message, context) {
11
+ this.display("info", message, api_logs_1.SeverityNumber.INFO, null, context);
12
+ }
13
+ warn(message, context) {
14
+ this.display("warn", message, api_logs_1.SeverityNumber.WARN, null, context);
15
+ }
16
+ error(message, error, context) {
17
+ this.display("error", message, api_logs_1.SeverityNumber.ERROR, error, context);
18
+ }
19
+ display(level, message, severityNumber = api_logs_1.SeverityNumber.INFO, error, context) {
20
+ var _a, _b;
21
+ let formattedMessage = message;
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ const attributes = { "log.type": "custom" };
24
+ formattedMessage = message;
25
+ if (error) {
26
+ attributes["exception.type"] = error.name;
27
+ attributes["exception.message"] = error.message;
28
+ attributes["exception.stacktrace"] = error.stack;
29
+ formattedMessage += "\n" + error.stack;
30
+ }
31
+ if (context) {
32
+ const spanCtx = context.spanContext();
33
+ if (spanCtx) {
34
+ attributes["span.id"] = spanCtx.spanId;
35
+ attributes["trace.id"] = spanCtx.traceId;
36
+ }
37
+ }
38
+ console.log(`[${level}] [${this.module}] ${formattedMessage}`);
39
+ if (!((_a = this.standardLogger) === null || _a === void 0 ? void 0 : _a.getLogger())) {
40
+ return;
41
+ }
42
+ (_b = this.standardLogger.getLogger()) === null || _b === void 0 ? void 0 : _b.emit({
43
+ severityNumber,
44
+ severityText: level,
45
+ body: `[${this.module}] ${formattedMessage}`,
46
+ attributes,
47
+ });
48
+ }
49
+ }
50
+ exports.ModuleLogger = ModuleLogger;
@@ -0,0 +1,11 @@
1
+ import type { Logger as OTelLogger } from "@opentelemetry/api-logs";
2
+ import { ConfigOTelInterface } from "./models/ConfigOTelInterface";
3
+ import { ModuleLogger } from "./ModuleLogger";
4
+ export declare class StandardLogger {
5
+ private logger?;
6
+ private serviceVersion?;
7
+ private serviceName?;
8
+ initOTel(config: ConfigOTelInterface): void;
9
+ getLogger(): OTelLogger | undefined;
10
+ createModuleLogger(moduleName: string): ModuleLogger;
11
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.StandardLogger = void 0;
37
+ const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
38
+ const resources_1 = require("@opentelemetry/resources");
39
+ const sdk_logs_1 = require("@opentelemetry/sdk-logs");
40
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
41
+ const os = __importStar(require("os"));
42
+ const ModuleLogger_1 = require("./ModuleLogger");
43
+ class StandardLogger {
44
+ initOTel(config) {
45
+ this.serviceName = config.SERVICE_ID;
46
+ this.serviceVersion = config.VERSION;
47
+ if (config.OPENTELEMETRY_COLLECTOR_HTTP_LOGS) {
48
+ const exporterHeaders = {};
49
+ if (config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER) {
50
+ exporterHeaders["Authorization"] = `Bearer ${config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER}`;
51
+ }
52
+ const exporter = new exporter_logs_otlp_http_1.OTLPLogExporter({
53
+ url: config.OPENTELEMETRY_COLLECTOR_HTTP_LOGS,
54
+ headers: exporterHeaders,
55
+ });
56
+ const loggerProvider = new sdk_logs_1.LoggerProvider({
57
+ processors: [
58
+ new sdk_logs_1.BatchLogRecordProcessor(exporter, {
59
+ maxQueueSize: 100,
60
+ scheduledDelayMillis: config.OPENTELEMETRY_COLLECTOR_EXPORT_LOGS_INTERVAL_SECONDS *
61
+ 1000,
62
+ }),
63
+ ],
64
+ resource: (0, resources_1.resourceFromAttributes)({
65
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: `${this.serviceName}`,
66
+ [semantic_conventions_1.ATTR_SERVICE_VERSION]: `${this.serviceVersion}`,
67
+ [semantic_conventions_1.ATTR_NETWORK_LOCAL_ADDRESS]: os.hostname(),
68
+ }),
69
+ });
70
+ this.logger = loggerProvider.getLogger(`${this.serviceName}:${this.serviceVersion}`);
71
+ }
72
+ }
73
+ getLogger() {
74
+ return this.logger;
75
+ }
76
+ createModuleLogger(moduleName) {
77
+ return new ModuleLogger_1.ModuleLogger(moduleName, this);
78
+ }
79
+ }
80
+ exports.StandardLogger = StandardLogger;
@@ -0,0 +1,12 @@
1
+ import { Counter, Histogram, ObservableGauge } from "@opentelemetry/api";
2
+ import { ConfigOTelInterface } from "./models/ConfigOTelInterface";
3
+ export declare class StandardMeter {
4
+ private meter;
5
+ private serviceVersion;
6
+ private serviceName;
7
+ constructor(config: ConfigOTelInterface);
8
+ createCounter(key: string): Counter;
9
+ createUpDownCounter(key: string): Counter;
10
+ createHistogram(key: string): Histogram;
11
+ createObservableGauge(key: string, callback: (observableResult: any) => void, description?: any): ObservableGauge;
12
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.StandardMeter = void 0;
37
+ const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http");
38
+ const resources_1 = require("@opentelemetry/resources");
39
+ const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
40
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
41
+ const os = __importStar(require("os"));
42
+ class StandardMeter {
43
+ constructor(config) {
44
+ this.serviceName = config.SERVICE_ID;
45
+ this.serviceVersion = config.VERSION;
46
+ let meterProvider;
47
+ if (config.OPENTELEMETRY_COLLECTOR_HTTP_METRICS) {
48
+ const collectorOptions = {
49
+ url: config.OPENTELEMETRY_COLLECTOR_HTTP_METRICS,
50
+ headers: {},
51
+ concurrencyLimit: 1,
52
+ };
53
+ if (config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER) {
54
+ collectorOptions.headers["Authorization"] = `Bearer ${config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER}`;
55
+ }
56
+ const metricExporter = new exporter_metrics_otlp_http_1.OTLPMetricExporter(collectorOptions);
57
+ meterProvider = new sdk_metrics_1.MeterProvider({
58
+ resource: (0, resources_1.resourceFromAttributes)({
59
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: `${this.serviceName}`,
60
+ [semantic_conventions_1.ATTR_SERVICE_VERSION]: `${this.serviceVersion}`,
61
+ [semantic_conventions_1.ATTR_NETWORK_LOCAL_ADDRESS]: os.hostname(),
62
+ }),
63
+ readers: [
64
+ new sdk_metrics_1.PeriodicExportingMetricReader({
65
+ exporter: metricExporter,
66
+ exportIntervalMillis: config.OPENTELEMETRY_COLLECTOR_EXPORT_METRICS_INTERVAL_SECONDS *
67
+ 1000,
68
+ }),
69
+ ],
70
+ });
71
+ }
72
+ else {
73
+ meterProvider = new sdk_metrics_1.MeterProvider({
74
+ resource: (0, resources_1.resourceFromAttributes)({
75
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: `${this.serviceName}`,
76
+ [semantic_conventions_1.ATTR_SERVICE_VERSION]: `${this.serviceVersion}`,
77
+ [semantic_conventions_1.ATTR_NETWORK_LOCAL_ADDRESS]: os.hostname(),
78
+ }),
79
+ });
80
+ }
81
+ this.meter = meterProvider.getMeter(`${this.serviceName}:${this.serviceVersion}`);
82
+ }
83
+ createCounter(key) {
84
+ return this.meter.createCounter(`${this.serviceName}.${key}`);
85
+ }
86
+ createUpDownCounter(key) {
87
+ return this.meter.createUpDownCounter(`${this.serviceName}.${key}`);
88
+ }
89
+ createHistogram(key) {
90
+ return this.meter.createHistogram(`${this.serviceName}.${key}`);
91
+ }
92
+ createObservableGauge(key,
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ callback,
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ description = null) {
97
+ const observableGauge = this.meter.createObservableGauge(key, description);
98
+ observableGauge.addCallback(callback);
99
+ return observableGauge;
100
+ }
101
+ }
102
+ exports.StandardMeter = StandardMeter;
@@ -0,0 +1,10 @@
1
+ import { Span } from "@opentelemetry/sdk-trace-base";
2
+ import { ConfigOTelInterface } from "./models/ConfigOTelInterface";
3
+ export declare class StandardTracer {
4
+ private tracer;
5
+ private serviceVersion;
6
+ private serviceName;
7
+ constructor(config: ConfigOTelInterface);
8
+ startSpan(name: string, parentSpan?: Span): Span;
9
+ static updateHttpHeader(context: Span, headers?: {}): any;
10
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.StandardTracer = void 0;
37
+ const api_1 = __importStar(require("@opentelemetry/api"));
38
+ const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
39
+ const core_1 = require("@opentelemetry/core");
40
+ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
41
+ const id_generator_aws_xray_1 = require("@opentelemetry/id-generator-aws-xray");
42
+ const resources_1 = require("@opentelemetry/resources");
43
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
44
+ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
45
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
46
+ const os = __importStar(require("os"));
47
+ class StandardTracer {
48
+ constructor(config) {
49
+ this.serviceName = config.SERVICE_ID;
50
+ this.serviceVersion = config.VERSION;
51
+ const spanProcessors = [];
52
+ if (config.OPENTELEMETRY_COLLECTOR_HTTP_TRACES) {
53
+ const exporterHeaders = {};
54
+ if (config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER) {
55
+ exporterHeaders["Authorization"] = `Bearer ${config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER}`;
56
+ }
57
+ const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
58
+ url: config.OPENTELEMETRY_COLLECTOR_HTTP_TRACES,
59
+ headers: exporterHeaders,
60
+ });
61
+ spanProcessors.push(new sdk_trace_base_1.BatchSpanProcessor(exporter));
62
+ }
63
+ const traceProvider = new sdk_trace_node_1.NodeTracerProvider({
64
+ idGenerator: new id_generator_aws_xray_1.AWSXRayIdGenerator(),
65
+ resource: (0, resources_1.resourceFromAttributes)({
66
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: `${this.serviceName}`,
67
+ [semantic_conventions_1.ATTR_SERVICE_VERSION]: `${this.serviceVersion}`,
68
+ [semantic_conventions_1.ATTR_NETWORK_LOCAL_ADDRESS]: os.hostname(),
69
+ }),
70
+ spanProcessors,
71
+ });
72
+ traceProvider.register();
73
+ const contextManager = new context_async_hooks_1.AsyncHooksContextManager();
74
+ contextManager.enable();
75
+ api_1.default.context.setGlobalContextManager(contextManager);
76
+ this.tracer = api_1.default.trace.getTracer(`${this.serviceName}:${this.serviceVersion}`);
77
+ }
78
+ startSpan(name, parentSpan) {
79
+ const sanitizedName = String(name).replace(/[^a-zA-Z0-9-_/]/g, "_");
80
+ if (parentSpan) {
81
+ return this.tracer.startSpan(sanitizedName, undefined, api_1.default.trace.setSpan(api_1.default.context.active(), parentSpan));
82
+ }
83
+ const span = this.tracer.startSpan(sanitizedName);
84
+ span.setAttribute(semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD, `BACKEND`);
85
+ span.setAttribute(semantic_conventions_1.ATTR_HTTP_ROUTE, `${this.serviceName}-${this.serviceVersion}-${sanitizedName}`);
86
+ return span;
87
+ }
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ static updateHttpHeader(context, headers = {}) {
90
+ if (!headers) {
91
+ headers = {};
92
+ }
93
+ const propagator = new core_1.W3CTraceContextPropagator();
94
+ propagator.inject(api_1.trace.setSpanContext(api_1.ROOT_CONTEXT, context.spanContext()),
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ headers, api_1.defaultTextMapSetter);
97
+ return headers;
98
+ }
99
+ }
100
+ exports.StandardTracer = StandardTracer;
@@ -0,0 +1,11 @@
1
+ export interface ConfigOTelInterface {
2
+ SERVICE_ID: string;
3
+ VERSION: string;
4
+ OPENTELEMETRY_COLLECTOR_HTTP_TRACES: string;
5
+ OPENTELEMETRY_COLLECTOR_HTTP_METRICS: string;
6
+ OPENTELEMETRY_COLLECTOR_HTTP_LOGS: string;
7
+ OPENTELEMETRY_COLLECTOR_EXPORT_LOGS_INTERVAL_SECONDS: number;
8
+ OPENTELEMETRY_COLLECTOR_EXPORT_METRICS_INTERVAL_SECONDS: number;
9
+ OPENTELEMETRY_COLLECTOR_AWS: boolean;
10
+ OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { Logger } from "@opentelemetry/api-logs";
2
+ export interface StandardLoggerInterface {
3
+ getLogger(): Logger | undefined;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devopsplaybook.io/otel-utils",
3
- "version": "1.0.5",
3
+ "version": "1.0.7-beta.6.01832d5",
4
4
  "description": "Utility to simplify integration with Open Telemetry",
5
5
  "keywords": [
6
6
  "Open",
@@ -20,24 +20,24 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@opentelemetry/api": "^1.9.0",
23
- "@opentelemetry/api-logs": "^0.204.0",
24
- "@opentelemetry/auto-instrumentations-node": "^0.63.0",
25
- "@opentelemetry/exporter-logs-otlp-http": "^0.204.0",
26
- "@opentelemetry/exporter-trace-otlp-http": "^0.204.0",
23
+ "@opentelemetry/api-logs": "^0.205.0",
24
+ "@opentelemetry/auto-instrumentations-node": "^0.64.1",
25
+ "@opentelemetry/exporter-logs-otlp-http": "^0.205.0",
26
+ "@opentelemetry/exporter-trace-otlp-http": "^0.205.0",
27
27
  "@opentelemetry/id-generator-aws-xray": "^2.0.1",
28
28
  "@opentelemetry/resources": "^2.1.0",
29
- "@opentelemetry/sdk-logs": "^0.204.0",
30
- "@opentelemetry/sdk-node": "^0.204.0",
29
+ "@opentelemetry/sdk-logs": "^0.205.0",
30
+ "@opentelemetry/sdk-node": "^0.205.0",
31
31
  "@opentelemetry/sdk-trace-base": "^2.1.0",
32
32
  "@opentelemetry/sdk-trace-web": "^2.1.0",
33
33
  "@opentelemetry/semantic-conventions": "^1.37.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@eslint/js": "^9.35.0",
37
- "@types/node": "^24.3.1",
36
+ "@eslint/js": "^9.36.0",
37
+ "@types/node": "^24.5.2",
38
38
  "@types/sqlite3": "^5.1.0",
39
39
  "ts-node": "^10.9.2",
40
- "typescript-eslint": "^8.43.0",
40
+ "typescript-eslint": "^8.44.1",
41
41
  "typescript": "^5.9.2"
42
42
  },
43
43
  "publishConfig": {