@opentelemetry/winston-transport 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,7 +35,9 @@ const winston = require('winston');
35
35
  // To start a logger, you first need to initialize the Logger provider.
36
36
  // And add a processor to export log record.
37
37
  const loggerProvider = new LoggerProvider({
38
- processors: [new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())],
38
+ processors: [
39
+ new SimpleLogRecordProcessor({ exporter: new ConsoleLogRecordExporter() })
40
+ ],
39
41
  });
40
42
  logsAPI.logs.setGlobalLoggerProvider(loggerProvider);
41
43
 
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.emitLogRecord = void 0;
8
8
  const api_logs_1 = require("@opentelemetry/api-logs");
9
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
9
10
  const npmLevels = {
10
11
  error: api_logs_1.SeverityNumber.ERROR,
11
12
  warn: api_logs_1.SeverityNumber.WARN,
@@ -156,6 +157,7 @@ function getExceptionPayload(record) {
156
157
  }
157
158
  function emitLogRecord(record, logger) {
158
159
  const { message, level, ...splat } = record;
160
+ const { [semantic_conventions_1.ATTR_OTEL_EVENT_NAME]: eventName, ...rest } = splat;
159
161
  const attributes = {};
160
162
  // Ensures the log level is read from a symbol property, avoiding any
161
163
  // accidental inclusion of ANSI color codes that may be present in the string
@@ -163,10 +165,10 @@ function emitLogRecord(record, logger) {
163
165
  const levelSym = record[Symbol.for('level')];
164
166
  const exceptionPayload = getExceptionPayload(record);
165
167
  const excludedAttributes = new Set(exceptionPayload?.excludedAttributes ?? []);
166
- for (const key in splat) {
167
- if (Object.prototype.hasOwnProperty.call(splat, key) &&
168
+ for (const key in rest) {
169
+ if (Object.prototype.hasOwnProperty.call(rest, key) &&
168
170
  !excludedAttributes.has(key)) {
169
- attributes[key] = splat[key];
171
+ attributes[key] = rest[key];
170
172
  }
171
173
  }
172
174
  if (exceptionPayload?.additionalAttributes) {
@@ -176,12 +178,16 @@ function emitLogRecord(record, logger) {
176
178
  }
177
179
  }
178
180
  }
181
+ const normalizedEventName = typeof eventName === 'string' ? eventName : undefined;
179
182
  const logRecord = {
180
183
  severityNumber: getSeverityNumber(levelSym),
181
184
  severityText: levelSym,
182
185
  body: message,
183
186
  attributes: attributes,
184
187
  ...(exceptionPayload ? { exception: exceptionPayload.exception } : {}),
188
+ ...(normalizedEventName !== undefined
189
+ ? { eventName: normalizedEventName }
190
+ : {}),
185
191
  };
186
192
  logger.emit(logRecord);
187
193
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,sDAMiC;AAEjC,MAAM,SAAS,GAA2B;IACxC,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,IAAI,EAAE,yBAAc,CAAC,MAAM;IAC3B,OAAO,EAAE,yBAAc,CAAC,MAAM;IAC9B,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,KAAK,EAAE,yBAAc,CAAC,KAAK;CAC5B,CAAC;AAEF,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,yBAAc,CAAC,MAAM;IAC5B,KAAK,EAAE,yBAAc,CAAC,MAAM;IAC5B,IAAI,EAAE,yBAAc,CAAC,KAAK;IAC1B,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,OAAO,EAAE,yBAAc,CAAC,IAAI;IAC5B,MAAM,EAAE,yBAAc,CAAC,KAAK;IAC5B,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,KAAK,EAAE,yBAAc,CAAC,KAAK;CAC5B,CAAC;AAEF,MAAM,SAAS,GAA2B;IACxC,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,IAAI,EAAE,yBAAc,CAAC,IAA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;SACF;KACF;IACD,MAAM,SAAS,GAAc;QAC3B,cAAc,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QAC3C,YAAY,EAAE,QAAQ;QACtB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,UAAU;QACtB,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC;AA1CD,sCA0CC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AnyValue,\n LogAttributes,\n LogRecord,\n Logger,\n SeverityNumber,\n} from '@opentelemetry/api-logs';\n\nconst npmLevels: Record<string, number> = {\n error: SeverityNumber.ERROR,\n warn: SeverityNumber.WARN,\n info: SeverityNumber.INFO,\n http: SeverityNumber.DEBUG3,\n verbose: SeverityNumber.DEBUG2,\n debug: SeverityNumber.DEBUG,\n silly: SeverityNumber.TRACE,\n};\n\nconst sysLoglevels: Record<string, number> = {\n emerg: SeverityNumber.FATAL3,\n alert: SeverityNumber.FATAL2,\n crit: SeverityNumber.FATAL,\n error: SeverityNumber.ERROR,\n warning: SeverityNumber.WARN,\n notice: SeverityNumber.INFO2,\n info: SeverityNumber.INFO,\n debug: SeverityNumber.DEBUG,\n};\n\nconst cliLevels: Record<string, number> = {\n error: SeverityNumber.ERROR,\n warn: SeverityNumber.WARN,\n help: SeverityNumber.INFO3,\n data: SeverityNumber.INFO2,\n info: SeverityNumber.INFO,\n debug: SeverityNumber.DEBUG,\n prompt: SeverityNumber.TRACE4,\n verbose: SeverityNumber.TRACE3,\n input: SeverityNumber.TRACE2,\n silly: SeverityNumber.TRACE,\n};\n\nfunction getSeverityNumber(level: string): SeverityNumber | undefined {\n return npmLevels[level] ?? sysLoglevels[level] ?? cliLevels[level];\n}\n\n/**\n * Mirrors the exception shapes handled by sdk-logs `LogRecordImpl._setException`.\n * We cannot reuse that internal method directly from this package.\n */\nfunction isSdkLogsExceptionCandidate(value: unknown): boolean {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n\n if (value == null || typeof value !== 'object') {\n return false;\n }\n\n const exception = value as {\n code?: unknown;\n name?: unknown;\n message?: unknown;\n stack?: unknown;\n };\n\n return (\n exception.code != null ||\n exception.name != null ||\n exception.message != null ||\n exception.stack != null\n );\n}\n\nfunction extractCauseAttributes(\n key: 'err' | 'error',\n value: unknown\n): LogAttributes {\n if (value == null || typeof value !== 'object' || !('cause' in value)) {\n return {};\n }\n\n const cause = (value as { cause: unknown }).cause;\n if (cause == null) {\n return {};\n }\n\n const attributes: LogAttributes = {};\n if (typeof cause === 'string' || typeof cause === 'number') {\n attributes[`${key}.cause`] = cause as AnyValue;\n return attributes;\n }\n\n if (typeof cause !== 'object') {\n attributes[`${key}.cause`] = String(cause);\n return attributes;\n }\n\n const exceptionCause = cause as {\n code?: unknown;\n name?: unknown;\n message?: unknown;\n stack?: unknown;\n };\n if (\n typeof exceptionCause.code === 'string' ||\n typeof exceptionCause.code === 'number'\n ) {\n attributes[`${key}.cause.code`] = exceptionCause.code;\n }\n if (typeof exceptionCause.name === 'string') {\n attributes[`${key}.cause.type`] = exceptionCause.name;\n }\n if (typeof exceptionCause.message === 'string') {\n attributes[`${key}.cause.message`] = exceptionCause.message;\n }\n if (typeof exceptionCause.stack === 'string') {\n attributes[`${key}.cause.stacktrace`] = exceptionCause.stack;\n }\n\n if (Object.keys(attributes).length === 0) {\n attributes[`${key}.cause`] = String(cause);\n }\n return attributes;\n}\n\n/**\n * Attempts to extract an exception/error from a Winston log record.\n *\n * Winston records can carry error information in several ways depending on\n * how the user logged and which formats are configured. This function checks\n * three sources in priority order:\n *\n * 1. Named fields ('err', 'error') used by user code and Winston internals.\n * 2. Splat args (Symbol.for('splat')) used for extra positional log args.\n * 3. Flattened stack fields produced by format.errors({ stack: true }).\n *\n * @returns The extracted exception, record keys that should be excluded from\n * OTel attributes to avoid duplication, and optional extra attributes\n * derived from the source error (for example `error.cause.*`).\n * Returns null if no error was found.\n */\nfunction getExceptionPayload(record: Record<string | symbol, any>): {\n exception: unknown;\n excludedAttributes: string[];\n additionalAttributes?: LogAttributes;\n} | null {\n for (const key of ['err', 'error'] as const) {\n const value = record[key];\n if (isSdkLogsExceptionCandidate(value)) {\n return {\n exception: value,\n excludedAttributes: [key],\n additionalAttributes: extractCauseAttributes(key, value),\n };\n }\n }\n\n const splat = record[Symbol.for('splat')];\n if (Array.isArray(splat)) {\n const splatException = splat.find(isSdkLogsExceptionCandidate);\n if (splatException !== undefined) {\n return {\n exception: splatException,\n excludedAttributes: [],\n };\n }\n }\n\n if (typeof record.stack === 'string') {\n const stackTypeMatch = /^([^:\\n]+):/.exec(record.stack);\n const exception: {\n code?: string | number;\n name?: string;\n message?: string;\n stack: string;\n } = {\n stack: record.stack,\n };\n if (typeof record.code === 'string' || typeof record.code === 'number') {\n exception.code = record.code;\n }\n if (typeof record.name === 'string') {\n exception.name = record.name;\n } else if (stackTypeMatch) {\n exception.name = stackTypeMatch[1];\n }\n if (typeof record.message === 'string') {\n exception.message = record.message;\n }\n return {\n exception,\n excludedAttributes: ['code', 'name', 'stack'],\n };\n }\n\n return null;\n}\n\nexport function emitLogRecord(\n record: Record<string | symbol, any>,\n logger: Logger\n): void {\n const { message, level, ...splat } = record;\n const attributes: LogAttributes = {};\n // Ensures the log level is read from a symbol property, avoiding any\n // accidental inclusion of ANSI color codes that may be present in the string\n // property.\n const levelSym = record[Symbol.for('level')];\n const exceptionPayload = getExceptionPayload(record);\n const excludedAttributes = new Set(\n exceptionPayload?.excludedAttributes ?? []\n );\n for (const key in splat) {\n if (\n Object.prototype.hasOwnProperty.call(splat, key) &&\n !excludedAttributes.has(key)\n ) {\n attributes[key] = splat[key];\n }\n }\n if (exceptionPayload?.additionalAttributes) {\n for (const key in exceptionPayload.additionalAttributes) {\n if (\n Object.prototype.hasOwnProperty.call(\n exceptionPayload.additionalAttributes,\n key\n )\n ) {\n attributes[key] = exceptionPayload.additionalAttributes[key];\n }\n }\n }\n const logRecord: LogRecord = {\n severityNumber: getSeverityNumber(levelSym),\n severityText: levelSym,\n body: message,\n attributes: attributes,\n ...(exceptionPayload ? { exception: exceptionPayload.exception } : {}),\n };\n logger.emit(logRecord);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,sDAMiC;AACjC,8EAA2E;AAE3E,MAAM,SAAS,GAA2B;IACxC,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,IAAI,EAAE,yBAAc,CAAC,MAAM;IAC3B,OAAO,EAAE,yBAAc,CAAC,MAAM;IAC9B,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,KAAK,EAAE,yBAAc,CAAC,KAAK;CAC5B,CAAC;AAEF,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,yBAAc,CAAC,MAAM;IAC5B,KAAK,EAAE,yBAAc,CAAC,MAAM;IAC5B,IAAI,EAAE,yBAAc,CAAC,KAAK;IAC1B,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,OAAO,EAAE,yBAAc,CAAC,IAAI;IAC5B,MAAM,EAAE,yBAAc,CAAC,KAAK;IAC5B,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,KAAK,EAAE,yBAAc,CAAC,KAAK;CAC5B,CAAC;AAEF,MAAM,SAAS,GAA2B;IACxC,KAAK,EAAE,yBAAc,CAAC,KAAK;IAC3B,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,IAAI,EAAE,yBAAc,CAAC,KAAK;IAC1B,IAAI,EAAE,yBAAc,CAAC,KAAK;IAC1B,IAAI,EAAE,yBAAc,CAAC,IAAI;IACzB,KA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GACvB,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAExD,MAAM,SAAS,GAAc;QAC3B,cAAc,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QAC3C,YAAY,EAAE,QAAQ;QACtB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,UAAU;QACtB,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,GAAG,CAAC,mBAAmB,KAAK,SAAS;YACnC,CAAC,CAAC,EAAE,SAAS,EAAE,mBAAmB,EAAE;YACpC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC;AAjDD,sCAiDC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AnyValue,\n LogAttributes,\n LogRecord,\n Logger,\n SeverityNumber,\n} from '@opentelemetry/api-logs';\nimport { ATTR_OTEL_EVENT_NAME } from '@opentelemetry/semantic-conventions';\n\nconst npmLevels: Record<string, number> = {\n error: SeverityNumber.ERROR,\n warn: SeverityNumber.WARN,\n info: SeverityNumber.INFO,\n http: SeverityNumber.DEBUG3,\n verbose: SeverityNumber.DEBUG2,\n debug: SeverityNumber.DEBUG,\n silly: SeverityNumber.TRACE,\n};\n\nconst sysLoglevels: Record<string, number> = {\n emerg: SeverityNumber.FATAL3,\n alert: SeverityNumber.FATAL2,\n crit: SeverityNumber.FATAL,\n error: SeverityNumber.ERROR,\n warning: SeverityNumber.WARN,\n notice: SeverityNumber.INFO2,\n info: SeverityNumber.INFO,\n debug: SeverityNumber.DEBUG,\n};\n\nconst cliLevels: Record<string, number> = {\n error: SeverityNumber.ERROR,\n warn: SeverityNumber.WARN,\n help: SeverityNumber.INFO3,\n data: SeverityNumber.INFO2,\n info: SeverityNumber.INFO,\n debug: SeverityNumber.DEBUG,\n prompt: SeverityNumber.TRACE4,\n verbose: SeverityNumber.TRACE3,\n input: SeverityNumber.TRACE2,\n silly: SeverityNumber.TRACE,\n};\n\nfunction getSeverityNumber(level: string): SeverityNumber | undefined {\n return npmLevels[level] ?? sysLoglevels[level] ?? cliLevels[level];\n}\n\n/**\n * Mirrors the exception shapes handled by sdk-logs `LogRecordImpl._setException`.\n * We cannot reuse that internal method directly from this package.\n */\nfunction isSdkLogsExceptionCandidate(value: unknown): boolean {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n\n if (value == null || typeof value !== 'object') {\n return false;\n }\n\n const exception = value as {\n code?: unknown;\n name?: unknown;\n message?: unknown;\n stack?: unknown;\n };\n\n return (\n exception.code != null ||\n exception.name != null ||\n exception.message != null ||\n exception.stack != null\n );\n}\n\nfunction extractCauseAttributes(\n key: 'err' | 'error',\n value: unknown\n): LogAttributes {\n if (value == null || typeof value !== 'object' || !('cause' in value)) {\n return {};\n }\n\n const cause = (value as { cause: unknown }).cause;\n if (cause == null) {\n return {};\n }\n\n const attributes: LogAttributes = {};\n if (typeof cause === 'string' || typeof cause === 'number') {\n attributes[`${key}.cause`] = cause as AnyValue;\n return attributes;\n }\n\n if (typeof cause !== 'object') {\n attributes[`${key}.cause`] = String(cause);\n return attributes;\n }\n\n const exceptionCause = cause as {\n code?: unknown;\n name?: unknown;\n message?: unknown;\n stack?: unknown;\n };\n if (\n typeof exceptionCause.code === 'string' ||\n typeof exceptionCause.code === 'number'\n ) {\n attributes[`${key}.cause.code`] = exceptionCause.code;\n }\n if (typeof exceptionCause.name === 'string') {\n attributes[`${key}.cause.type`] = exceptionCause.name;\n }\n if (typeof exceptionCause.message === 'string') {\n attributes[`${key}.cause.message`] = exceptionCause.message;\n }\n if (typeof exceptionCause.stack === 'string') {\n attributes[`${key}.cause.stacktrace`] = exceptionCause.stack;\n }\n\n if (Object.keys(attributes).length === 0) {\n attributes[`${key}.cause`] = String(cause);\n }\n return attributes;\n}\n\n/**\n * Attempts to extract an exception/error from a Winston log record.\n *\n * Winston records can carry error information in several ways depending on\n * how the user logged and which formats are configured. This function checks\n * three sources in priority order:\n *\n * 1. Named fields ('err', 'error') used by user code and Winston internals.\n * 2. Splat args (Symbol.for('splat')) used for extra positional log args.\n * 3. Flattened stack fields produced by format.errors({ stack: true }).\n *\n * @returns The extracted exception, record keys that should be excluded from\n * OTel attributes to avoid duplication, and optional extra attributes\n * derived from the source error (for example `error.cause.*`).\n * Returns null if no error was found.\n */\nfunction getExceptionPayload(record: Record<string | symbol, any>): {\n exception: unknown;\n excludedAttributes: string[];\n additionalAttributes?: LogAttributes;\n} | null {\n for (const key of ['err', 'error'] as const) {\n const value = record[key];\n if (isSdkLogsExceptionCandidate(value)) {\n return {\n exception: value,\n excludedAttributes: [key],\n additionalAttributes: extractCauseAttributes(key, value),\n };\n }\n }\n\n const splat = record[Symbol.for('splat')];\n if (Array.isArray(splat)) {\n const splatException = splat.find(isSdkLogsExceptionCandidate);\n if (splatException !== undefined) {\n return {\n exception: splatException,\n excludedAttributes: [],\n };\n }\n }\n\n if (typeof record.stack === 'string') {\n const stackTypeMatch = /^([^:\\n]+):/.exec(record.stack);\n const exception: {\n code?: string | number;\n name?: string;\n message?: string;\n stack: string;\n } = {\n stack: record.stack,\n };\n if (typeof record.code === 'string' || typeof record.code === 'number') {\n exception.code = record.code;\n }\n if (typeof record.name === 'string') {\n exception.name = record.name;\n } else if (stackTypeMatch) {\n exception.name = stackTypeMatch[1];\n }\n if (typeof record.message === 'string') {\n exception.message = record.message;\n }\n return {\n exception,\n excludedAttributes: ['code', 'name', 'stack'],\n };\n }\n\n return null;\n}\n\nexport function emitLogRecord(\n record: Record<string | symbol, any>,\n logger: Logger\n): void {\n const { message, level, ...splat } = record;\n const { [ATTR_OTEL_EVENT_NAME]: eventName, ...rest } = splat;\n const attributes: LogAttributes = {};\n // Ensures the log level is read from a symbol property, avoiding any\n // accidental inclusion of ANSI color codes that may be present in the string\n // property.\n const levelSym = record[Symbol.for('level')];\n const exceptionPayload = getExceptionPayload(record);\n const excludedAttributes = new Set(\n exceptionPayload?.excludedAttributes ?? []\n );\n for (const key in rest) {\n if (\n Object.prototype.hasOwnProperty.call(rest, key) &&\n !excludedAttributes.has(key)\n ) {\n attributes[key] = rest[key];\n }\n }\n if (exceptionPayload?.additionalAttributes) {\n for (const key in exceptionPayload.additionalAttributes) {\n if (\n Object.prototype.hasOwnProperty.call(\n exceptionPayload.additionalAttributes,\n key\n )\n ) {\n attributes[key] = exceptionPayload.additionalAttributes[key];\n }\n }\n }\n const normalizedEventName =\n typeof eventName === 'string' ? eventName : undefined;\n\n const logRecord: LogRecord = {\n severityNumber: getSeverityNumber(levelSym),\n severityText: levelSym,\n body: message,\n attributes: attributes,\n ...(exceptionPayload ? { exception: exceptionPayload.exception } : {}),\n ...(normalizedEventName !== undefined\n ? { eventName: normalizedEventName }\n : {}),\n };\n logger.emit(logRecord);\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.29.0";
1
+ export declare const PACKAGE_VERSION = "0.30.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/winston-transport";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -6,6 +6,6 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
8
8
  // this is autogenerated file, see scripts/version-update.js
9
- exports.PACKAGE_VERSION = '0.29.0';
9
+ exports.PACKAGE_VERSION = '0.30.0';
10
10
  exports.PACKAGE_NAME = '@opentelemetry/winston-transport';
11
11
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,kCAAkC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.29.0';\nexport const PACKAGE_NAME = '@opentelemetry/winston-transport';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,kCAAkC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.30.0';\nexport const PACKAGE_NAME = '@opentelemetry/winston-transport';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/winston-transport",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "OpenTelemetry Transport for winston",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -39,13 +39,14 @@
39
39
  "access": "public"
40
40
  },
41
41
  "devDependencies": {
42
- "@opentelemetry/sdk-logs": "^0.219.0",
42
+ "@opentelemetry/sdk-logs": "^0.220.0",
43
43
  "@types/triple-beam": "1.3.5"
44
44
  },
45
45
  "dependencies": {
46
- "@opentelemetry/api-logs": "^0.219.0",
46
+ "@opentelemetry/api-logs": "^0.220.0",
47
+ "@opentelemetry/semantic-conventions": "^1.41.1",
47
48
  "winston-transport": "4.*"
48
49
  },
49
50
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/winston-transport#readme",
50
- "gitHead": "4e52a9053029304f271b7dbe1b07e7fb2b987e30"
51
+ "gitHead": "8d7daea5c404855f474a82f4296640af8b93b64c"
51
52
  }