@sebspark/otel 0.3.1 → 0.4.2

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/dist/index.d.mts CHANGED
@@ -7,7 +7,7 @@ declare function getLogger(serviceOverride?: string, extraAttrs?: Attrs): {
7
7
  info: (msg: string, attrs?: Attrs) => void;
8
8
  notice: (msg: string, attrs?: Attrs) => void;
9
9
  warn: (msg: string, attrs?: Attrs) => void;
10
- error: (msg: string | Error, attrs?: Attrs) => void;
10
+ error: (msg: string | Error, errOrAttrs?: Error | Attrs, maybeAttrs?: Attrs) => void;
11
11
  critical: (msg: string, attrs?: Attrs) => void;
12
12
  alert: (msg: string, attrs?: Attrs) => void;
13
13
  emergency: (msg: string, attrs?: Attrs) => void;
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ declare function getLogger(serviceOverride?: string, extraAttrs?: Attrs): {
7
7
  info: (msg: string, attrs?: Attrs) => void;
8
8
  notice: (msg: string, attrs?: Attrs) => void;
9
9
  warn: (msg: string, attrs?: Attrs) => void;
10
- error: (msg: string | Error, attrs?: Attrs) => void;
10
+ error: (msg: string | Error, errOrAttrs?: Error | Attrs, maybeAttrs?: Attrs) => void;
11
11
  critical: (msg: string, attrs?: Attrs) => void;
12
12
  alert: (msg: string, attrs?: Attrs) => void;
13
13
  emergency: (msg: string, attrs?: Attrs) => void;
package/dist/index.js CHANGED
@@ -539,13 +539,27 @@ var TreeSpanProcessor = class {
539
539
 
540
540
  // src/providers.ts
541
541
  var getLogProvider = (resource, otlpEndpoint) => {
542
- const exporter = otlpEndpoint ? new import_exporter_logs_otlp_http.OTLPLogExporter({ url: `${otlpEndpoint}/v1/logs` }) : new ConsoleLogPrettyExporter();
543
- const processor = otlpEndpoint ? new import_sdk_logs.BatchLogRecordProcessor(exporter) : new import_sdk_logs.SimpleLogRecordProcessor(exporter);
544
- const provider = new import_sdk_logs.LoggerProvider({
542
+ if (otlpEndpoint) {
543
+ const exporter2 = new import_exporter_logs_otlp_http.OTLPLogExporter({ url: `${otlpEndpoint}/v1/logs` });
544
+ const processors = [
545
+ new import_sdk_logs.BatchLogRecordProcessor(exporter2)
546
+ ];
547
+ if (process.env.LOG_LEVEL) {
548
+ processors.push(
549
+ new import_sdk_logs.SimpleLogRecordProcessor(new ConsoleLogPrettyExporter())
550
+ );
551
+ }
552
+ return new import_sdk_logs.LoggerProvider({
553
+ resource,
554
+ processors
555
+ });
556
+ }
557
+ const exporter = new ConsoleLogPrettyExporter();
558
+ const processor = new import_sdk_logs.SimpleLogRecordProcessor(exporter);
559
+ return new import_sdk_logs.LoggerProvider({
545
560
  resource,
546
561
  processors: [processor]
547
562
  });
548
- return provider;
549
563
  };
550
564
  var getSpanProcessor = (otlpEndpoint) => {
551
565
  const exporter = otlpEndpoint ? new import_exporter_trace_otlp_http.OTLPTraceExporter({
@@ -699,8 +713,16 @@ function getLogger(serviceOverride, extraAttrs = {}) {
699
713
  info: (msg, attrs) => emit("INFO", msg, attrs),
700
714
  notice: (msg, attrs) => emit("NOTICE", msg, attrs),
701
715
  warn: (msg, attrs) => emit("WARNING", msg, attrs),
702
- error: (msg, attrs = {}) => {
703
- const body = msg instanceof Error ? msg.stack || msg.message : msg;
716
+ error: (msg, errOrAttrs, maybeAttrs = {}) => {
717
+ let body;
718
+ let attrs;
719
+ if (errOrAttrs instanceof Error) {
720
+ body = `${msg}: ${errOrAttrs.stack || errOrAttrs.message}`;
721
+ attrs = maybeAttrs;
722
+ } else {
723
+ body = msg instanceof Error ? msg.stack || msg.message : msg;
724
+ attrs = errOrAttrs || {};
725
+ }
704
726
  emit("ERROR", body, attrs);
705
727
  },
706
728
  critical: (msg, attrs) => emit("CRITICAL", msg, attrs),
package/dist/index.mjs CHANGED
@@ -510,13 +510,27 @@ var TreeSpanProcessor = class {
510
510
 
511
511
  // src/providers.ts
512
512
  var getLogProvider = (resource, otlpEndpoint) => {
513
- const exporter = otlpEndpoint ? new OTLPLogExporter({ url: `${otlpEndpoint}/v1/logs` }) : new ConsoleLogPrettyExporter();
514
- const processor = otlpEndpoint ? new BatchLogRecordProcessor(exporter) : new SimpleLogRecordProcessor(exporter);
515
- const provider = new LoggerProvider({
513
+ if (otlpEndpoint) {
514
+ const exporter2 = new OTLPLogExporter({ url: `${otlpEndpoint}/v1/logs` });
515
+ const processors = [
516
+ new BatchLogRecordProcessor(exporter2)
517
+ ];
518
+ if (process.env.LOG_LEVEL) {
519
+ processors.push(
520
+ new SimpleLogRecordProcessor(new ConsoleLogPrettyExporter())
521
+ );
522
+ }
523
+ return new LoggerProvider({
524
+ resource,
525
+ processors
526
+ });
527
+ }
528
+ const exporter = new ConsoleLogPrettyExporter();
529
+ const processor = new SimpleLogRecordProcessor(exporter);
530
+ return new LoggerProvider({
516
531
  resource,
517
532
  processors: [processor]
518
533
  });
519
- return provider;
520
534
  };
521
535
  var getSpanProcessor = (otlpEndpoint) => {
522
536
  const exporter = otlpEndpoint ? new OTLPTraceExporter({
@@ -676,8 +690,16 @@ function getLogger(serviceOverride, extraAttrs = {}) {
676
690
  info: (msg, attrs) => emit("INFO", msg, attrs),
677
691
  notice: (msg, attrs) => emit("NOTICE", msg, attrs),
678
692
  warn: (msg, attrs) => emit("WARNING", msg, attrs),
679
- error: (msg, attrs = {}) => {
680
- const body = msg instanceof Error ? msg.stack || msg.message : msg;
693
+ error: (msg, errOrAttrs, maybeAttrs = {}) => {
694
+ let body;
695
+ let attrs;
696
+ if (errOrAttrs instanceof Error) {
697
+ body = `${msg}: ${errOrAttrs.stack || errOrAttrs.message}`;
698
+ attrs = maybeAttrs;
699
+ } else {
700
+ body = msg instanceof Error ? msg.stack || msg.message : msg;
701
+ attrs = errOrAttrs || {};
702
+ }
681
703
  emit("ERROR", body, attrs);
682
704
  },
683
705
  critical: (msg, attrs) => emit("CRITICAL", msg, attrs),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/otel",
3
- "version": "0.3.1",
3
+ "version": "0.4.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",