@effect/opentelemetry 4.0.0-beta.8 → 4.0.0-beta.81

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/src/WebSdk.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser OpenTelemetry setup for Effect applications.
3
+ *
4
+ * This module exports a `Configuration` type and layers for installing
5
+ * tracing, metrics, and logging in browser runtimes. The main `layer` builds
6
+ * the shared OpenTelemetry resource from explicit service metadata, then
7
+ * enables only the signal types that have processors or readers configured.
8
+ * `layerTracerProvider` creates a scoped `WebTracerProvider`.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import type * as Otel from "@opentelemetry/api"
5
13
  import type { LoggerProviderConfig, LogRecordProcessor } from "@opentelemetry/sdk-logs"
@@ -17,8 +25,10 @@ import * as Resource from "./Resource.ts"
17
25
  import * as Tracer from "./Tracer.ts"
18
26
 
19
27
  /**
20
- * @since 1.0.0
21
- * @category Models
28
+ * Configuration for the Web OpenTelemetry layer, including resource metadata and optional tracing, metrics, and logging settings.
29
+ *
30
+ * @category models
31
+ * @since 4.0.0
22
32
  */
23
33
  export interface Configuration {
24
34
  readonly spanProcessor?: SpanProcessor | ReadonlyArray<SpanProcessor> | undefined
@@ -36,8 +46,10 @@ export interface Configuration {
36
46
  }
37
47
 
38
48
  /**
39
- * @since 1.0.0
40
- * @category Layers
49
+ * Creates a scoped Web OpenTelemetry tracer provider from one or more span processors and shuts it down when the layer is released.
50
+ *
51
+ * @category layers
52
+ * @since 4.0.0
41
53
  */
42
54
  export const layerTracerProvider = (
43
55
  processor: SpanProcessor | NonEmptyReadonlyArray<SpanProcessor>,
@@ -65,18 +77,75 @@ export const layerTracerProvider = (
65
77
  )
66
78
 
67
79
  /**
68
- * @since 1.0.0
69
- * @category Layers
80
+ * Creates a Web OpenTelemetry layer from configuration, providing the resource and enabling tracing, metrics, and logging when configured.
81
+ *
82
+ * **When to use**
83
+ *
84
+ * Use to install browser OpenTelemetry support when service metadata is
85
+ * configured in code and telemetry processors or readers are supplied directly.
86
+ *
87
+ * **Details**
88
+ *
89
+ * The configuration can be provided lazily or effectfully. The layer always
90
+ * provides `Resource.Resource`; tracing, metrics, and logging are installed only
91
+ * when the corresponding processors or readers are non-empty.
92
+ *
93
+ * **Gotchas**
94
+ *
95
+ * Browser resource metadata is explicit; this layer does not read
96
+ * OpenTelemetry environment variables. Empty processor or reader arrays are
97
+ * treated as not configured.
98
+ *
99
+ * @category layers
100
+ * @since 4.0.0
70
101
  */
71
102
  export const layer: {
72
103
  /**
73
- * @since 1.0.0
74
- * @category Layers
104
+ * Creates a Web OpenTelemetry layer from configuration, providing the resource and enabling tracing, metrics, and logging when configured.
105
+ *
106
+ * **When to use**
107
+ *
108
+ * Use to install browser OpenTelemetry support when service metadata is
109
+ * configured in code and telemetry processors or readers are supplied directly.
110
+ *
111
+ * **Details**
112
+ *
113
+ * The configuration can be provided lazily or effectfully. The layer always
114
+ * provides `Resource.Resource`; tracing, metrics, and logging are installed only
115
+ * when the corresponding processors or readers are non-empty.
116
+ *
117
+ * **Gotchas**
118
+ *
119
+ * Browser resource metadata is explicit; this layer does not read
120
+ * OpenTelemetry environment variables. Empty processor or reader arrays are
121
+ * treated as not configured.
122
+ *
123
+ * @category layers
124
+ * @since 4.0.0
75
125
  */
76
126
  (evaluate: LazyArg<Configuration>): Layer.Layer<Resource.Resource>
77
127
  /**
78
- * @since 1.0.0
79
- * @category Layers
128
+ * Creates a Web OpenTelemetry layer from configuration, providing the resource and enabling tracing, metrics, and logging when configured.
129
+ *
130
+ * **When to use**
131
+ *
132
+ * Use to install browser OpenTelemetry support when service metadata is
133
+ * configured in code and telemetry processors or readers are supplied directly.
134
+ *
135
+ * **Details**
136
+ *
137
+ * The configuration can be provided lazily or effectfully. The layer always
138
+ * provides `Resource.Resource`; tracing, metrics, and logging are installed only
139
+ * when the corresponding processors or readers are non-empty.
140
+ *
141
+ * **Gotchas**
142
+ *
143
+ * Browser resource metadata is explicit; this layer does not read
144
+ * OpenTelemetry environment variables. Empty processor or reader arrays are
145
+ * treated as not configured.
146
+ *
147
+ * @category layers
148
+ * @since 4.0.0
80
149
  */
81
150
  <E, R>(evaluate: Effect.Effect<Configuration, E, R>): Layer.Layer<Resource.Resource, E, R>
82
151
  } = (
package/src/index.ts CHANGED
@@ -1,35 +1,35 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * @since 4.0.0
9
9
  */
10
10
  export * as Logger from "./Logger.ts"
11
11
 
12
12
  /**
13
- * @since 1.0.0
13
+ * @since 4.0.0
14
14
  */
15
15
  export * as Metrics from "./Metrics.ts"
16
16
 
17
17
  /**
18
- * @since 1.0.0
18
+ * @since 4.0.0
19
19
  */
20
20
  export * as NodeSdk from "./NodeSdk.ts"
21
21
 
22
22
  /**
23
- * @since 1.0.0
23
+ * @since 4.0.0
24
24
  */
25
25
  export * as Resource from "./Resource.ts"
26
26
 
27
27
  /**
28
- * @since 1.0.0
28
+ * @since 4.0.0
29
29
  */
30
30
  export * as Tracer from "./Tracer.ts"
31
31
 
32
32
  /**
33
- * @since 1.0.0
33
+ * @since 4.0.0
34
34
  */
35
35
  export * as WebSdk from "./WebSdk.ts"
@@ -1,6 +1,13 @@
1
1
  import type * as Otel from "@opentelemetry/api"
2
2
  import * as Inspectable from "effect/Inspectable"
3
3
 
4
+ const bigint1e9 = BigInt(1_000_000_000)
5
+
6
+ /** @internal */
7
+ export const nanosToHrTime = (timestamp: bigint): Otel.HrTime => {
8
+ return [Number(timestamp / bigint1e9), Number(timestamp % bigint1e9)]
9
+ }
10
+
4
11
  /** @internal */
5
12
  export const recordToAttributes = (record: Record<string, unknown>): Otel.Attributes => {
6
13
  const attributes: Otel.Attributes = {}
@@ -11,8 +11,8 @@ import type {
11
11
  import { AggregationTemporality, DataPointType, InstrumentType } from "@opentelemetry/sdk-metrics"
12
12
  import type { InstrumentDescriptor } from "@opentelemetry/sdk-metrics/build/src/InstrumentDescriptor.js"
13
13
  import * as Arr from "effect/Array"
14
+ import type * as Context from "effect/Context"
14
15
  import * as Metric from "effect/Metric"
15
- import type * as ServiceMap from "effect/ServiceMap"
16
16
  import type * as Metrics from "../Metrics.ts"
17
17
 
18
18
  const sdkName = "@effect/opentelemetry/Metrics"
@@ -37,7 +37,7 @@ interface PreviousSummaryState {
37
37
  /** @internal */
38
38
  export class MetricProducerImpl implements MetricProducer {
39
39
  resource: Resources.Resource
40
- services: ServiceMap.ServiceMap<never>
40
+ context: Context.Context<never>
41
41
  temporality: Metrics.TemporalityPreference
42
42
  startTimes: Map<string, HrTime>
43
43
  startTimeNanos: HrTime
@@ -49,11 +49,11 @@ export class MetricProducerImpl implements MetricProducer {
49
49
 
50
50
  constructor(
51
51
  resource: Resources.Resource,
52
- services: ServiceMap.ServiceMap<never>,
52
+ context: Context.Context<never>,
53
53
  temporality: Metrics.TemporalityPreference = "cumulative"
54
54
  ) {
55
55
  this.resource = resource
56
- this.services = services
56
+ this.context = context
57
57
  this.temporality = temporality
58
58
  this.startTimes = new Map()
59
59
  this.startTimeNanos = currentHrTime()
@@ -73,7 +73,7 @@ export class MetricProducerImpl implements MetricProducer {
73
73
  }
74
74
 
75
75
  collect(_options?: MetricCollectOptions): Promise<CollectionResult> {
76
- const snapshot = Metric.snapshotUnsafe(this.services)
76
+ const snapshot = Metric.snapshotUnsafe(this.context)
77
77
  const hrTimeNow = currentHrTime()
78
78
  const metricData: Array<MetricData> = []
79
79
  const metricDataByName = new Map<string, MetricData>()
@@ -111,7 +111,7 @@ export class MetricProducerImpl implements MetricProducer {
111
111
  if (typeof currentCount === "bigint" && typeof previousCount === "bigint") {
112
112
  reportValue = currentCount - previousCount
113
113
  // Handle reset: if current < previous, report current value
114
- if (reportValue < 0n) {
114
+ if (reportValue < BigInt(0)) {
115
115
  reportValue = currentCount
116
116
  }
117
117
  } else {