pragma-log-manager-aws-lambda 1.0.0 → 1.1.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.
@@ -1,3 +1,7 @@
1
1
  import * as winston from "winston";
2
2
  import './tracing';
3
+ export declare const getCurrentTrace: () => {
4
+ traceId: string;
5
+ spanId: string;
6
+ };
3
7
  export declare const logger: winston.Logger;
@@ -33,17 +33,32 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.logger = void 0;
36
+ exports.logger = exports.getCurrentTrace = void 0;
37
37
  const winston = __importStar(require("winston"));
38
38
  const moment = __importStar(require("moment-timezone"));
39
39
  require("./tracing");
40
- const tracing_1 = require("./tracing");
40
+ const api_1 = require("@opentelemetry/api");
41
+ const getCurrentTrace = () => {
42
+ const activeSpan = api_1.trace.getActiveSpan();
43
+ if (!activeSpan) {
44
+ return {
45
+ traceId: 'no-trace-id',
46
+ spanId: 'no-span-id',
47
+ };
48
+ }
49
+ const spanContext = activeSpan.spanContext();
50
+ return {
51
+ traceId: spanContext.traceId,
52
+ spanId: spanContext.spanId,
53
+ };
54
+ };
55
+ exports.getCurrentTrace = getCurrentTrace;
41
56
  exports.logger = winston.createLogger({
42
57
  level: 'info',
43
58
  format: winston.format.combine(winston.format.timestamp({
44
59
  format: () => moment.tz('America/Bogota').format('YYYY-MM-DDTHH:mm:ss.SSS')
45
60
  }), winston.format.printf(({ level, message, timestamp, ...obj }) => {
46
- const { traceId, spanId } = (0, tracing_1.getCurrentTrace)();
61
+ const { traceId, spanId } = (0, exports.getCurrentTrace)();
47
62
  const payload = obj.action;
48
63
  const error = obj.error;
49
64
  const transactionId = obj.transactionId;
@@ -1,5 +1 @@
1
1
  export declare const tracer: import("@opentelemetry/api").Tracer;
2
- export declare const getCurrentTrace: () => {
3
- traceId: string;
4
- spanId: string;
5
- };
@@ -1,51 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCurrentTrace = exports.tracer = void 0;
4
- const sdk_node_1 = require("@opentelemetry/sdk-node");
3
+ exports.tracer = void 0;
4
+ const api_1 = require("@opentelemetry/api");
5
5
  const resources_1 = require("@opentelemetry/resources");
6
6
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
7
+ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
8
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
7
9
  const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
8
- const instrumentation_aws_lambda_1 = require("@opentelemetry/instrumentation-aws-lambda");
9
- const api_1 = require("@opentelemetry/api");
10
- let sdk = null;
11
- const initializeSDK = () => {
12
- if (sdk)
13
- return sdk;
14
- const traceExporter = process.env.OTEL_EXPORTER_OTLP_ENDPOINT
15
- ? new exporter_trace_otlp_http_1.OTLPTraceExporter({ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT })
16
- : undefined;
17
- sdk = new sdk_node_1.NodeSDK({
18
- resource: new resources_1.Resource({
19
- [semantic_conventions_1.ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'default-lambda',
20
- }),
21
- instrumentations: [
22
- new instrumentation_aws_lambda_1.AwsLambdaInstrumentation()
10
+ let initialized = false;
11
+ const initializeTracing = () => {
12
+ if (initialized)
13
+ return;
14
+ const resource = (0, resources_1.resourceFromAttributes)({
15
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'default-lambda',
16
+ });
17
+ const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
18
+ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
19
+ });
20
+ const provider = new sdk_trace_node_1.NodeTracerProvider({
21
+ resource,
22
+ spanProcessors: [
23
+ new sdk_trace_base_1.BatchSpanProcessor(exporter),
23
24
  ],
24
- traceExporter: traceExporter
25
25
  });
26
- sdk.start();
27
- return sdk;
26
+ provider.register();
27
+ initialized = true;
28
28
  };
29
- // Initialize SDK
30
- initializeSDK();
29
+ initializeTracing();
31
30
  exports.tracer = api_1.trace.getTracer('default-tracer');
32
- const getCurrentTrace = () => {
33
- const activeSpan = api_1.trace.getActiveSpan();
34
- if (!activeSpan) {
35
- return {
36
- traceId: 'no-trace-id',
37
- spanId: 'no-span-id'
38
- };
39
- }
40
- const spanContext = activeSpan.spanContext();
41
- return {
42
- traceId: spanContext.traceId,
43
- spanId: spanContext.spanId
44
- };
45
- };
46
- exports.getCurrentTrace = getCurrentTrace;
47
- process.on('SIGTERM', () => {
48
- if (sdk) {
49
- sdk.shutdown().then();
50
- }
51
- });
@@ -1,3 +1,7 @@
1
1
  import * as winston from "winston";
2
2
  import './tracing';
3
+ export declare const getCurrentTrace: () => {
4
+ traceId: string;
5
+ spanId: string;
6
+ };
3
7
  export declare const logger: winston.Logger;
@@ -1,7 +1,21 @@
1
1
  import * as winston from "winston";
2
2
  import * as moment from "moment-timezone";
3
3
  import './tracing';
4
- import { getCurrentTrace } from "./tracing";
4
+ import { trace } from "@opentelemetry/api";
5
+ export const getCurrentTrace = () => {
6
+ const activeSpan = trace.getActiveSpan();
7
+ if (!activeSpan) {
8
+ return {
9
+ traceId: 'no-trace-id',
10
+ spanId: 'no-span-id',
11
+ };
12
+ }
13
+ const spanContext = activeSpan.spanContext();
14
+ return {
15
+ traceId: spanContext.traceId,
16
+ spanId: spanContext.spanId,
17
+ };
18
+ };
5
19
  export const logger = winston.createLogger({
6
20
  level: 'info',
7
21
  format: winston.format.combine(winston.format.timestamp({
@@ -1,5 +1 @@
1
1
  export declare const tracer: import("@opentelemetry/api").Tracer;
2
- export declare const getCurrentTrace: () => {
3
- traceId: string;
4
- spanId: string;
5
- };
@@ -1,47 +1,27 @@
1
- import { NodeSDK } from '@opentelemetry/sdk-node';
2
- import { Resource } from '@opentelemetry/resources';
1
+ import { trace } from '@opentelemetry/api';
2
+ import { resourceFromAttributes } from '@opentelemetry/resources';
3
3
  import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
4
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
5
+ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
4
6
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
5
- import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
6
- import { trace } from '@opentelemetry/api';
7
- let sdk = null;
8
- const initializeSDK = () => {
9
- if (sdk)
10
- return sdk;
11
- const traceExporter = process.env.OTEL_EXPORTER_OTLP_ENDPOINT
12
- ? new OTLPTraceExporter({ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT })
13
- : undefined;
14
- sdk = new NodeSDK({
15
- resource: new Resource({
16
- [ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'default-lambda',
17
- }),
18
- instrumentations: [
19
- new AwsLambdaInstrumentation()
7
+ let initialized = false;
8
+ const initializeTracing = () => {
9
+ if (initialized)
10
+ return;
11
+ const resource = resourceFromAttributes({
12
+ [ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'default-lambda',
13
+ });
14
+ const exporter = new OTLPTraceExporter({
15
+ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
16
+ });
17
+ const provider = new NodeTracerProvider({
18
+ resource,
19
+ spanProcessors: [
20
+ new BatchSpanProcessor(exporter),
20
21
  ],
21
- traceExporter: traceExporter
22
22
  });
23
- sdk.start();
24
- return sdk;
23
+ provider.register();
24
+ initialized = true;
25
25
  };
26
- // Initialize SDK
27
- initializeSDK();
26
+ initializeTracing();
28
27
  export const tracer = trace.getTracer('default-tracer');
29
- export const getCurrentTrace = () => {
30
- const activeSpan = trace.getActiveSpan();
31
- if (!activeSpan) {
32
- return {
33
- traceId: 'no-trace-id',
34
- spanId: 'no-span-id'
35
- };
36
- }
37
- const spanContext = activeSpan.spanContext();
38
- return {
39
- traceId: spanContext.traceId,
40
- spanId: spanContext.spanId
41
- };
42
- };
43
- process.on('SIGTERM', () => {
44
- if (sdk) {
45
- sdk.shutdown().then();
46
- }
47
- });
@@ -1,3 +1,7 @@
1
1
  import * as winston from "winston";
2
2
  import './tracing';
3
+ export declare const getCurrentTrace: () => {
4
+ traceId: string;
5
+ spanId: string;
6
+ };
3
7
  export declare const logger: winston.Logger;
@@ -1,5 +1 @@
1
1
  export declare const tracer: import("@opentelemetry/api").Tracer;
2
- export declare const getCurrentTrace: () => {
3
- traceId: string;
4
- spanId: string;
5
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pragma-log-manager-aws-lambda",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "commonjs",
5
5
  "description": "OTEL - Winston implementation tracing for aws node lambdas in js",
6
6
  "author": "juan.ojeda@pragma.com.co",
@@ -22,25 +22,25 @@
22
22
  "build:types": "tsc --project tsconfig.types.json"
23
23
  },
24
24
  "peerDependencies": {
25
- "@opentelemetry/api": "^1.9.0",
26
- "@opentelemetry/auto-instrumentations-node": "^0.52.0",
27
- "@opentelemetry/exporter-trace-otlp-http": "^0.52.0",
28
- "@opentelemetry/instrumentation-aws-lambda": "^0.52.0",
29
- "@opentelemetry/resources": "^1.19.0",
30
- "@opentelemetry/sdk-node": "^0.52.1",
31
- "@opentelemetry/semantic-conventions": "^1.19.0",
32
- "winston": "^3.17.0"
25
+ "@opentelemetry/api": "1.9.0",
26
+ "@opentelemetry/resources": "2.1.0",
27
+ "@opentelemetry/sdk-trace-base": "2.1.0",
28
+ "@opentelemetry/sdk-trace-node": "2.1.0",
29
+ "@opentelemetry/exporter-trace-otlp-http": "0.215.0",
30
+ "@opentelemetry/semantic-conventions": "1.37.0",
31
+ "winston": "3.17.0"
33
32
  },
34
33
  "devDependencies": {
34
+ "@types/aws-lambda": "^8.10.92",
35
35
  "typescript": "^5.4.0"
36
36
  },
37
37
  "dependencies": {
38
- "moment-timezone": "^0.6.0"
38
+ "moment-timezone": "0.6.0"
39
39
  },
40
40
  "overrides": {
41
- "protobufjs": "^7.5.5"
41
+ "uuid": "14.0.0"
42
42
  },
43
43
  "resolutions": {
44
- "protobufjs": "^7.5.5"
44
+ "uuid": "14.0.0"
45
45
  }
46
46
  }