@sebspark/otel 1.0.0 → 1.0.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/README.md CHANGED
@@ -51,11 +51,11 @@ Automatically:
51
51
  ### Logging
52
52
 
53
53
  ```ts
54
- // Will throw if OTEL is not yet initialized
55
54
  import { getLogger } from '@sebspark/otel'
56
55
 
57
56
  const logger = getLogger()
58
57
 
58
+ // Will throw if OTEL is not yet initialized
59
59
  logger.debug('debug message')
60
60
  logger.info('something happened')
61
61
  logger.warn('almost bad')
package/dist/index.js CHANGED
@@ -763,6 +763,7 @@ async function _initialize(instrumentations2) {
763
763
  const serviceName = process.env.OTEL_SERVICE_NAME ?? "unknown-service";
764
764
  const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
765
765
  const resource = await getResource();
766
+ import_api3.context.disable();
766
767
  import_api_logs2.logs.disable();
767
768
  import_api3.trace.disable();
768
769
  import_api3.metrics.disable();
@@ -791,15 +792,15 @@ async function _initialize(instrumentations2) {
791
792
 
792
793
  // src/logger.ts
793
794
  function getLogger(serviceOverride, extraAttrs = {}) {
794
- if (!isInitialized()) {
795
- throw new Error("OTEL must be initialized before calling getLogger()");
796
- }
797
795
  const { systemName, systemVersion, resourceAttributes } = detectTelemetryContext(serviceOverride);
798
796
  const defaultAttrs = {
799
797
  ...resourceAttributes,
800
798
  ...extraAttrs
801
799
  };
802
800
  function emit(severityText, body, attrs = {}) {
801
+ if (!isInitialized()) {
802
+ throw new Error("OTEL must be initialized before calling getLogger()");
803
+ }
803
804
  const logger = import_api_logs3.logs.getLogger(systemName, systemVersion);
804
805
  const span = import_api4.trace.getSpan(import_api4.context.active());
805
806
  const spanContext = span?.spanContext();
package/dist/index.mjs CHANGED
@@ -75,7 +75,7 @@ var instrumentations = {
75
75
  };
76
76
 
77
77
  // src/logger.ts
78
- import { context, trace as trace2 } from "@opentelemetry/api";
78
+ import { context as context2, trace as trace2 } from "@opentelemetry/api";
79
79
  import { logs as logs2 } from "@opentelemetry/api-logs";
80
80
 
81
81
  // src/consts.ts
@@ -95,6 +95,7 @@ var LOG_SEVERITY_MAP = {
95
95
 
96
96
  // src/otel.ts
97
97
  import {
98
+ context,
98
99
  DiagConsoleLogger,
99
100
  DiagLogLevel,
100
101
  diag,
@@ -747,6 +748,7 @@ async function _initialize(instrumentations2) {
747
748
  const serviceName = process.env.OTEL_SERVICE_NAME ?? "unknown-service";
748
749
  const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
749
750
  const resource = await getResource();
751
+ context.disable();
750
752
  logs.disable();
751
753
  trace.disable();
752
754
  metrics.disable();
@@ -775,17 +777,17 @@ async function _initialize(instrumentations2) {
775
777
 
776
778
  // src/logger.ts
777
779
  function getLogger(serviceOverride, extraAttrs = {}) {
778
- if (!isInitialized()) {
779
- throw new Error("OTEL must be initialized before calling getLogger()");
780
- }
781
780
  const { systemName, systemVersion, resourceAttributes } = detectTelemetryContext(serviceOverride);
782
781
  const defaultAttrs = {
783
782
  ...resourceAttributes,
784
783
  ...extraAttrs
785
784
  };
786
785
  function emit(severityText, body, attrs = {}) {
786
+ if (!isInitialized()) {
787
+ throw new Error("OTEL must be initialized before calling getLogger()");
788
+ }
787
789
  const logger = logs2.getLogger(systemName, systemVersion);
788
- const span = trace2.getSpan(context.active());
790
+ const span = trace2.getSpan(context2.active());
789
791
  const spanContext = span?.spanContext();
790
792
  logger.emit({
791
793
  severityText,
@@ -838,7 +840,7 @@ function getMeter(componentNameOverride) {
838
840
 
839
841
  // src/tracer.ts
840
842
  import {
841
- context as context2,
843
+ context as context3,
842
844
  SpanStatusCode as SpanStatusCode3,
843
845
  trace as trace3
844
846
  } from "@opentelemetry/api";
@@ -859,9 +861,9 @@ function getTracer(componentNameOverride) {
859
861
  spanOrFunc,
860
862
  func
861
863
  );
862
- const parentContext = parent ? trace3.setSpan(context2.active(), parent) : context2.active();
864
+ const parentContext = parent ? trace3.setSpan(context3.active(), parent) : context3.active();
863
865
  const span = tracer.startSpan(name, options, parentContext);
864
- return await context2.with(trace3.setSpan(parentContext, span), async () => {
866
+ return await context3.with(trace3.setSpan(parentContext, span), async () => {
865
867
  try {
866
868
  const result = await fn(span);
867
869
  span.setStatus({ code: SpanStatusCode3.OK });
@@ -882,9 +884,9 @@ function getTracer(componentNameOverride) {
882
884
  spanOrFunc,
883
885
  func
884
886
  );
885
- const parentContext = parent ? trace3.setSpan(context2.active(), parent) : context2.active();
887
+ const parentContext = parent ? trace3.setSpan(context3.active(), parent) : context3.active();
886
888
  const span = tracer.startSpan(name, options, parentContext);
887
- return context2.with(trace3.setSpan(parentContext, span), () => {
889
+ return context3.with(trace3.setSpan(parentContext, span), () => {
888
890
  try {
889
891
  const result = fn(span);
890
892
  span.setStatus({ code: SpanStatusCode3.OK });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/otel",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",