@effect/opentelemetry 0.46.3 → 0.46.5

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.
Files changed (53) hide show
  1. package/Otlp/package.json +6 -0
  2. package/OtlpLogger/package.json +6 -0
  3. package/OtlpMetrics/package.json +6 -0
  4. package/OtlpResource/package.json +6 -0
  5. package/dist/cjs/Otlp.js +38 -0
  6. package/dist/cjs/Otlp.js.map +1 -0
  7. package/dist/cjs/OtlpLogger.js +153 -0
  8. package/dist/cjs/OtlpLogger.js.map +1 -0
  9. package/dist/cjs/OtlpMetrics.js +354 -0
  10. package/dist/cjs/OtlpMetrics.js.map +1 -0
  11. package/dist/cjs/OtlpResource.js +93 -0
  12. package/dist/cjs/OtlpResource.js.map +1 -0
  13. package/dist/cjs/OtlpTracer.js +45 -130
  14. package/dist/cjs/OtlpTracer.js.map +1 -1
  15. package/dist/cjs/index.js +9 -1
  16. package/dist/cjs/internal/otlpExporter.js +81 -0
  17. package/dist/cjs/internal/otlpExporter.js.map +1 -0
  18. package/dist/dts/Otlp.d.ts +29 -0
  19. package/dist/dts/Otlp.d.ts.map +1 -0
  20. package/dist/dts/OtlpLogger.d.ts +39 -0
  21. package/dist/dts/OtlpLogger.d.ts.map +1 -0
  22. package/dist/dts/OtlpMetrics.d.ts +38 -0
  23. package/dist/dts/OtlpMetrics.d.ts.map +1 -0
  24. package/dist/dts/OtlpResource.d.ts +89 -0
  25. package/dist/dts/OtlpResource.d.ts.map +1 -0
  26. package/dist/dts/OtlpTracer.d.ts +6 -3
  27. package/dist/dts/OtlpTracer.d.ts.map +1 -1
  28. package/dist/dts/index.d.ts +17 -0
  29. package/dist/dts/index.d.ts.map +1 -1
  30. package/dist/dts/internal/otlpExporter.d.ts +2 -0
  31. package/dist/dts/internal/otlpExporter.d.ts.map +1 -0
  32. package/dist/esm/Otlp.js +29 -0
  33. package/dist/esm/Otlp.js.map +1 -0
  34. package/dist/esm/OtlpLogger.js +144 -0
  35. package/dist/esm/OtlpLogger.js.map +1 -0
  36. package/dist/esm/OtlpMetrics.js +345 -0
  37. package/dist/esm/OtlpMetrics.js.map +1 -0
  38. package/dist/esm/OtlpResource.js +81 -0
  39. package/dist/esm/OtlpResource.js.map +1 -0
  40. package/dist/esm/OtlpTracer.js +42 -126
  41. package/dist/esm/OtlpTracer.js.map +1 -1
  42. package/dist/esm/index.js +17 -0
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/internal/otlpExporter.js +73 -0
  45. package/dist/esm/internal/otlpExporter.js.map +1 -0
  46. package/package.json +35 -3
  47. package/src/Otlp.ts +56 -0
  48. package/src/OtlpLogger.ts +243 -0
  49. package/src/OtlpMetrics.ts +568 -0
  50. package/src/OtlpResource.ts +168 -0
  51. package/src/OtlpTracer.ts +54 -185
  52. package/src/index.ts +21 -0
  53. package/src/internal/otlpExporter.ts +114 -0
@@ -0,0 +1,345 @@
1
+ import * as Arr from "effect/Array";
2
+ import * as Duration from "effect/Duration";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Metric from "effect/Metric";
6
+ import * as MetricState from "effect/MetricState";
7
+ import * as Option from "effect/Option";
8
+ import * as Exporter from "./internal/otlpExporter.js";
9
+ import * as OtlpResource from "./OtlpResource.js";
10
+ /**
11
+ * @since 1.0.0
12
+ * @category Constructors
13
+ */
14
+ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
15
+ const clock = yield* Effect.clock;
16
+ const startTime = String(clock.unsafeCurrentTimeNanos());
17
+ const resource = OtlpResource.make(options.resource);
18
+ const metricsScope = {
19
+ name: options.resource.serviceName
20
+ };
21
+ const snapshot = () => {
22
+ const snapshot = Metric.unsafeSnapshot();
23
+ const nowNanos = clock.unsafeCurrentTimeNanos();
24
+ const nowTime = String(nowNanos);
25
+ const metricData = [];
26
+ const metricDataByName = new Map();
27
+ const addMetricData = data => {
28
+ metricData.push(data);
29
+ metricDataByName.set(data.name, data);
30
+ };
31
+ for (let i = 0, len = snapshot.length; i < len; i++) {
32
+ const {
33
+ metricKey,
34
+ metricState
35
+ } = snapshot[i];
36
+ let unit = "1";
37
+ const attributes = Arr.reduce(metricKey.tags, [], (acc, label) => {
38
+ if (label.key === "unit" || label.key === "time_unit") {
39
+ unit = label.value;
40
+ }
41
+ acc.push({
42
+ key: label.key,
43
+ value: {
44
+ stringValue: label.value
45
+ }
46
+ });
47
+ return acc;
48
+ });
49
+ if (MetricState.isCounterState(metricState)) {
50
+ const dataPoint = {
51
+ attributes,
52
+ startTimeUnixNano: startTime,
53
+ timeUnixNano: nowTime
54
+ };
55
+ if (typeof metricState.count === "bigint") {
56
+ dataPoint.asInt = Number(metricState.count);
57
+ } else {
58
+ dataPoint.asDouble = metricState.count;
59
+ }
60
+ if (metricDataByName.has(metricKey.name)) {
61
+ metricDataByName.get(metricKey.name).sum.dataPoints.push(dataPoint);
62
+ } else {
63
+ const key = metricKey;
64
+ addMetricData({
65
+ name: metricKey.name,
66
+ description: getOrEmpty(key.description),
67
+ unit,
68
+ sum: {
69
+ aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE,
70
+ isMonotonic: key.keyType.incremental,
71
+ dataPoints: [dataPoint]
72
+ }
73
+ });
74
+ }
75
+ } else if (MetricState.isGaugeState(metricState)) {
76
+ const dataPoint = {
77
+ attributes,
78
+ startTimeUnixNano: startTime,
79
+ timeUnixNano: nowTime
80
+ };
81
+ if (typeof metricState.value === "bigint") {
82
+ dataPoint.asInt = Number(metricState.value);
83
+ } else {
84
+ dataPoint.asDouble = metricState.value;
85
+ }
86
+ if (metricDataByName.has(metricKey.name)) {
87
+ metricDataByName.get(metricKey.name).gauge.dataPoints.push(dataPoint);
88
+ } else {
89
+ addMetricData({
90
+ name: metricKey.name,
91
+ description: getOrEmpty(metricKey.description),
92
+ unit,
93
+ gauge: {
94
+ dataPoints: [dataPoint]
95
+ }
96
+ });
97
+ }
98
+ } else if (MetricState.isHistogramState(metricState)) {
99
+ const size = metricState.buckets.length;
100
+ const buckets = {
101
+ boundaries: Arr.allocate(size - 1),
102
+ counts: Arr.allocate(size)
103
+ };
104
+ let i = 0;
105
+ let prev = 0;
106
+ for (const [boundary, value] of metricState.buckets) {
107
+ if (i < size - 1) {
108
+ buckets.boundaries[i] = boundary;
109
+ }
110
+ buckets.counts[i] = value - prev;
111
+ prev = value;
112
+ i++;
113
+ }
114
+ const dataPoint = {
115
+ attributes,
116
+ startTimeUnixNano: startTime,
117
+ timeUnixNano: nowTime,
118
+ count: metricState.count,
119
+ min: metricState.min,
120
+ max: metricState.max,
121
+ sum: metricState.sum,
122
+ bucketCounts: buckets.counts,
123
+ explicitBounds: buckets.boundaries
124
+ };
125
+ if (metricDataByName.has(metricKey.name)) {
126
+ metricDataByName.get(metricKey.name).histogram.dataPoints.push(dataPoint);
127
+ } else {
128
+ addMetricData({
129
+ name: metricKey.name,
130
+ description: getOrEmpty(metricKey.description),
131
+ unit,
132
+ histogram: {
133
+ aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE,
134
+ dataPoints: [dataPoint]
135
+ }
136
+ });
137
+ }
138
+ } else if (MetricState.isFrequencyState(metricState)) {
139
+ const dataPoints = [];
140
+ for (const [freqKey, value] of metricState.occurrences) {
141
+ dataPoints.push({
142
+ attributes: [...attributes, {
143
+ key: "key",
144
+ value: {
145
+ stringValue: freqKey
146
+ }
147
+ }],
148
+ startTimeUnixNano: startTime,
149
+ timeUnixNano: nowTime,
150
+ asInt: value
151
+ });
152
+ }
153
+ if (metricDataByName.has(metricKey.name)) {
154
+ // eslint-disable-next-line no-restricted-syntax
155
+ metricDataByName.get(metricKey.name).sum.dataPoints.push(...dataPoints);
156
+ } else {
157
+ addMetricData({
158
+ name: metricKey.name,
159
+ description: getOrEmpty(metricKey.description),
160
+ unit,
161
+ sum: {
162
+ aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE,
163
+ isMonotonic: true,
164
+ dataPoints
165
+ }
166
+ });
167
+ }
168
+ } else if (MetricState.isSummaryState(metricState)) {
169
+ const dataPoints = [{
170
+ attributes: [...attributes, {
171
+ key: "quantile",
172
+ value: {
173
+ stringValue: "min"
174
+ }
175
+ }],
176
+ startTimeUnixNano: startTime,
177
+ timeUnixNano: nowTime,
178
+ asDouble: metricState.min
179
+ }];
180
+ for (const [quantile, value] of metricState.quantiles) {
181
+ dataPoints.push({
182
+ attributes: [...attributes, {
183
+ key: "quantile",
184
+ value: {
185
+ stringValue: quantile.toString()
186
+ }
187
+ }],
188
+ startTimeUnixNano: startTime,
189
+ timeUnixNano: nowTime,
190
+ asDouble: value._tag === "Some" ? value.value : 0
191
+ });
192
+ }
193
+ dataPoints.push({
194
+ attributes: [...attributes, {
195
+ key: "quantile",
196
+ value: {
197
+ stringValue: "max"
198
+ }
199
+ }],
200
+ startTimeUnixNano: startTime,
201
+ timeUnixNano: nowTime,
202
+ asDouble: metricState.max
203
+ });
204
+ const countDataPoint = {
205
+ attributes,
206
+ startTimeUnixNano: startTime,
207
+ timeUnixNano: nowTime,
208
+ asInt: metricState.count
209
+ };
210
+ const sumDataPoint = {
211
+ attributes,
212
+ startTimeUnixNano: startTime,
213
+ timeUnixNano: nowTime,
214
+ asDouble: metricState.sum
215
+ };
216
+ if (metricDataByName.has(`${metricKey.name}_quantiles`)) {
217
+ // eslint-disable-next-line no-restricted-syntax
218
+ metricDataByName.get(`${metricKey.name}_quantiles`).sum.dataPoints.push(...dataPoints);
219
+ metricDataByName.get(`${metricKey.name}_count`).sum.dataPoints.push(countDataPoint);
220
+ metricDataByName.get(`${metricKey.name}_sum`).sum.dataPoints.push(sumDataPoint);
221
+ } else {
222
+ addMetricData({
223
+ name: `${metricKey.name}_quantiles`,
224
+ description: getOrEmpty(metricKey.description),
225
+ unit,
226
+ sum: {
227
+ aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE,
228
+ isMonotonic: false,
229
+ dataPoints
230
+ }
231
+ });
232
+ addMetricData({
233
+ name: `${metricKey.name}_count`,
234
+ description: getOrEmpty(metricKey.description),
235
+ unit: "1",
236
+ sum: {
237
+ aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE,
238
+ isMonotonic: true,
239
+ dataPoints: [countDataPoint]
240
+ }
241
+ });
242
+ addMetricData({
243
+ name: `${metricKey.name}_sum`,
244
+ description: getOrEmpty(metricKey.description),
245
+ unit: "1",
246
+ sum: {
247
+ aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE,
248
+ isMonotonic: true,
249
+ dataPoints: [sumDataPoint]
250
+ }
251
+ });
252
+ }
253
+ }
254
+ }
255
+ return {
256
+ resourceMetrics: [{
257
+ resource,
258
+ scopeMetrics: [{
259
+ scope: metricsScope,
260
+ metrics: metricData
261
+ }]
262
+ }]
263
+ };
264
+ };
265
+ yield* Exporter.make({
266
+ label: "OtlpMetrics",
267
+ url: options.url,
268
+ headers: options.headers,
269
+ maxBatchSize: "disabled",
270
+ exportInterval: options.exportInterval ?? Duration.seconds(10),
271
+ body: snapshot
272
+ });
273
+ });
274
+ /**
275
+ * @since 1.0.0
276
+ * @category Layers
277
+ */
278
+ export const layer = options => Layer.scopedDiscard(make(options));
279
+ // internal
280
+ const getOrEmpty = /*#__PURE__*/Option.getOrElse(() => "");
281
+ /**
282
+ * AggregationTemporality defines how a metric aggregator reports aggregated
283
+ * values. It describes how those values relate to the time interval over
284
+ * which they are aggregated.
285
+ */
286
+ var EAggregationTemporality;
287
+ (function (EAggregationTemporality) {
288
+ EAggregationTemporality[EAggregationTemporality["AGGREGATION_TEMPORALITY_UNSPECIFIED"] = 0] = "AGGREGATION_TEMPORALITY_UNSPECIFIED";
289
+ /** DELTA is an AggregationTemporality for a metric aggregator which reports
290
+ changes since last report time. Successive metrics contain aggregation of
291
+ values from continuous and non-overlapping intervals.
292
+ The values for a DELTA metric are based only on the time interval
293
+ associated with one measurement cycle. There is no dependency on
294
+ previous measurements like is the case for CUMULATIVE metrics.
295
+ For example, consider a system measuring the number of requests that
296
+ it receives and reports the sum of these requests every second as a
297
+ DELTA metric:
298
+ 1. The system starts receiving at time=t_0.
299
+ 2. A request is received, the system measures 1 request.
300
+ 3. A request is received, the system measures 1 request.
301
+ 4. A request is received, the system measures 1 request.
302
+ 5. The 1 second collection cycle ends. A metric is exported for the
303
+ number of requests received over the interval of time t_0 to
304
+ t_0+1 with a value of 3.
305
+ 6. A request is received, the system measures 1 request.
306
+ 7. A request is received, the system measures 1 request.
307
+ 8. The 1 second collection cycle ends. A metric is exported for the
308
+ number of requests received over the interval of time t_0+1 to
309
+ t_0+2 with a value of 2. */
310
+ EAggregationTemporality[EAggregationTemporality["AGGREGATION_TEMPORALITY_DELTA"] = 1] = "AGGREGATION_TEMPORALITY_DELTA";
311
+ /** CUMULATIVE is an AggregationTemporality for a metric aggregator which
312
+ reports changes since a fixed start time. This means that current values
313
+ of a CUMULATIVE metric depend on all previous measurements since the
314
+ start time. Because of this, the sender is required to retain this state
315
+ in some form. If this state is lost or invalidated, the CUMULATIVE metric
316
+ values MUST be reset and a new fixed start time following the last
317
+ reported measurement time sent MUST be used.
318
+ For example, consider a system measuring the number of requests that
319
+ it receives and reports the sum of these requests every second as a
320
+ CUMULATIVE metric:
321
+ 1. The system starts receiving at time=t_0.
322
+ 2. A request is received, the system measures 1 request.
323
+ 3. A request is received, the system measures 1 request.
324
+ 4. A request is received, the system measures 1 request.
325
+ 5. The 1 second collection cycle ends. A metric is exported for the
326
+ number of requests received over the interval of time t_0 to
327
+ t_0+1 with a value of 3.
328
+ 6. A request is received, the system measures 1 request.
329
+ 7. A request is received, the system measures 1 request.
330
+ 8. The 1 second collection cycle ends. A metric is exported for the
331
+ number of requests received over the interval of time t_0 to
332
+ t_0+2 with a value of 5.
333
+ 9. The system experiences a fault and loses state.
334
+ 10. The system recovers and resumes receiving at time=t_1.
335
+ 11. A request is received, the system measures 1 request.
336
+ 12. The 1 second collection cycle ends. A metric is exported for the
337
+ number of requests received over the interval of time t_1 to
338
+ t_0+1 with a value of 1.
339
+ Note: Even though, when reporting changes since last report time, using
340
+ CUMULATIVE is valid, it is not recommended. This may cause problems for
341
+ systems that do not use start_time to determine when the aggregation
342
+ value was reset (e.g. Prometheus). */
343
+ EAggregationTemporality[EAggregationTemporality["AGGREGATION_TEMPORALITY_CUMULATIVE"] = 2] = "AGGREGATION_TEMPORALITY_CUMULATIVE";
344
+ })(EAggregationTemporality || (EAggregationTemporality = {}));
345
+ //# sourceMappingURL=OtlpMetrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OtlpMetrics.js","names":["Arr","Duration","Effect","Layer","Metric","MetricState","Option","Exporter","OtlpResource","make","fnUntraced","options","clock","startTime","String","unsafeCurrentTimeNanos","resource","metricsScope","name","serviceName","snapshot","unsafeSnapshot","nowNanos","nowTime","metricData","metricDataByName","Map","addMetricData","data","push","set","i","len","length","metricKey","metricState","unit","attributes","reduce","tags","acc","label","key","value","stringValue","isCounterState","dataPoint","startTimeUnixNano","timeUnixNano","count","asInt","Number","asDouble","has","get","sum","dataPoints","description","getOrEmpty","aggregationTemporality","EAggregationTemporality","AGGREGATION_TEMPORALITY_CUMULATIVE","isMonotonic","keyType","incremental","isGaugeState","gauge","isHistogramState","size","buckets","boundaries","allocate","counts","prev","boundary","min","max","bucketCounts","explicitBounds","histogram","isFrequencyState","freqKey","occurrences","isSummaryState","quantile","quantiles","toString","_tag","countDataPoint","sumDataPoint","resourceMetrics","scopeMetrics","scope","metrics","url","headers","maxBatchSize","exportInterval","seconds","body","layer","scopedDiscard","getOrElse"],"sources":["../../src/OtlpMetrics.ts"],"sourcesContent":[null],"mappings":"AAKA,OAAO,KAAKA,GAAG,MAAM,cAAc;AACnC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eA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,EAAErE;SACV;OACF;KACF;EACH,CAAC;EAED,OAAOjB,QAAQ,CAACE,IAAI,CAAC;IACnBgC,KAAK,EAAE,aAAa;IACpBqD,GAAG,EAAEnF,OAAO,CAACmF,GAAG;IAChBC,OAAO,EAAEpF,OAAO,CAACoF,OAAO;IACxBC,YAAY,EAAE,UAAU;IACxBC,cAAc,EAAEtF,OAAO,CAACsF,cAAc,IAAIhG,QAAQ,CAACiG,OAAO,CAAC,EAAE,CAAC;IAC9DC,IAAI,EAAE/E;GACP,CAAC;AACJ,CAAC,CAAC;AAEF;;;;AAIA,OAAO,MAAMgF,KAAK,GAAIzF,OASrB,IAAuDR,KAAK,CAACkG,aAAa,CAAC5F,IAAI,CAACE,OAAO,CAAC,CAAC;AAE1F;AAEA,MAAM+C,UAAU,gBAAGpD,MAAM,CAACgG,SAAS,CAAC,MAAM,EAAE,CAAC;AA8M7C;;;;;AAKA,IAAW1C,uBA+DV;AA/DD,WAAWA,uBAAuB;EAChCA,uBAAA,CAAAA,uBAAA,oFAAuC;EACvC;;;;;;;;;;;;;;;;;;;;;EAwBAA,uBAAA,CAAAA,uBAAA,wEAAiC;EACjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCAA,uBAAA,CAAAA,uBAAA,kFAAsC;AACxC,CAAC,EA/DUA,uBAAuB,KAAvBA,uBAAuB","ignoreList":[]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Inspectable from "effect/Inspectable";
5
+ /**
6
+ * @since 1.0.0
7
+ * @category Constructors
8
+ */
9
+ export const make = options => {
10
+ const resourceAttributes = options.attributes ? entriesToAttributes(Object.entries(options.attributes)) : [];
11
+ resourceAttributes.push({
12
+ key: "service.name",
13
+ value: {
14
+ stringValue: options.serviceName
15
+ }
16
+ });
17
+ if (options.serviceVersion) {
18
+ resourceAttributes.push({
19
+ key: "service.version",
20
+ value: {
21
+ stringValue: options.serviceVersion
22
+ }
23
+ });
24
+ }
25
+ return {
26
+ attributes: resourceAttributes,
27
+ droppedAttributesCount: 0
28
+ };
29
+ };
30
+ /**
31
+ * @since 1.0.0
32
+ * @category Attributes
33
+ */
34
+ export const entriesToAttributes = entries => {
35
+ const attributes = [];
36
+ for (const [key, value] of entries) {
37
+ attributes.push({
38
+ key,
39
+ value: unknownToAttributeValue(value)
40
+ });
41
+ }
42
+ return attributes;
43
+ };
44
+ /**
45
+ * @since 1.0.0
46
+ * @category Attributes
47
+ */
48
+ export const unknownToAttributeValue = value => {
49
+ if (Array.isArray(value)) {
50
+ return {
51
+ arrayValue: {
52
+ values: value.map(unknownToAttributeValue)
53
+ }
54
+ };
55
+ }
56
+ switch (typeof value) {
57
+ case "string":
58
+ return {
59
+ stringValue: value
60
+ };
61
+ case "bigint":
62
+ return {
63
+ intValue: Number(value)
64
+ };
65
+ case "number":
66
+ return Number.isInteger(value) ? {
67
+ intValue: value
68
+ } : {
69
+ doubleValue: value
70
+ };
71
+ case "boolean":
72
+ return {
73
+ boolValue: value
74
+ };
75
+ default:
76
+ return {
77
+ stringValue: Inspectable.toStringUnknown(value)
78
+ };
79
+ }
80
+ };
81
+ //# sourceMappingURL=OtlpResource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OtlpResource.js","names":["Inspectable","make","options","resourceAttributes","attributes","entriesToAttributes","Object","entries","push","key","value","stringValue","serviceName","serviceVersion","droppedAttributesCount","unknownToAttributeValue","Array","isArray","arrayValue","values","map","intValue","Number","isInteger","doubleValue","boolValue","toStringUnknown"],"sources":["../../src/OtlpResource.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,WAAW,MAAM,oBAAoB;AAajD;;;;AAIA,OAAO,MAAMC,IAAI,GAAIC,OAIpB,IAAc;EACb,MAAMC,kBAAkB,GAAGD,OAAO,CAACE,UAAU,GACzCC,mBAAmB,CAACC,MAAM,CAACC,OAAO,CAACL,OAAO,CAACE,UAAU,CAAC,CAAC,GACvD,EAAE;EACND,kBAAkB,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AAe,CAAChB,KAAK;OAC/C;EACL;AACF,CAAC","ignoreList":[]}
@@ -1,99 +1,40 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- import * as Headers from "@effect/platform/Headers";
5
- import * as HttpBody from "@effect/platform/HttpBody";
6
- import * as HttpClient from "@effect/platform/HttpClient";
7
- import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
8
1
  import * as Cause from "effect/Cause";
9
2
  import * as Duration from "effect/Duration";
10
3
  import * as Effect from "effect/Effect";
11
- import * as FiberSet from "effect/FiberSet";
12
- import * as Inspectable from "effect/Inspectable";
13
4
  import * as Layer from "effect/Layer";
14
5
  import * as Option from "effect/Option";
15
- import * as Schedule from "effect/Schedule";
16
- import * as Scope from "effect/Scope";
17
6
  import * as Tracer from "effect/Tracer";
7
+ import * as Exporter from "./internal/otlpExporter.js";
8
+ import { entriesToAttributes } from "./OtlpResource.js";
9
+ import * as OtlpResource from "./OtlpResource.js";
18
10
  /**
19
11
  * @since 1.0.0
20
12
  * @category Constructors
21
13
  */
22
14
  export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
23
- const exporterScope = yield* Effect.scope;
24
- const exportInterval = options.exportInterval ? Duration.decode(options.exportInterval) : Duration.seconds(5);
25
- const maxBatchSize = options.maxBatchSize ?? 1000;
26
- const client = HttpClient.filterStatusOk(yield* HttpClient.HttpClient).pipe(HttpClient.tapError(error => {
27
- if (error._tag !== "ResponseError" || error.response.status !== 429) {
28
- return Effect.void;
29
- }
30
- const retryAfter = error.response.headers["retry-after"];
31
- const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : 5;
32
- return Effect.sleep(Duration.seconds(retryAfterSeconds));
33
- }), HttpClient.retryTransient({
34
- schedule: Schedule.spaced(1000)
35
- }));
36
- let headers = Headers.unsafeFromRecord({
37
- "user-agent": "@effect-opentelemetry-OtlpExporter"
38
- });
39
- if (options.headers) {
40
- headers = Headers.merge(Headers.fromInput(options.headers), headers);
41
- }
42
- const resourceAttributes = options.resource.attributes ? entriesToAttributes(Object.entries(options.resource.attributes)) : [];
43
- resourceAttributes.push({
44
- key: "service.name",
45
- value: {
46
- stringValue: options.resource.serviceName
47
- }
48
- });
49
- if (options.resource.serviceVersion) {
50
- resourceAttributes.push({
51
- key: "service.version",
52
- value: {
53
- stringValue: options.resource.serviceVersion
54
- }
55
- });
56
- }
57
- const otelResource = {
58
- attributes: resourceAttributes,
59
- droppedAttributesCount: 0
60
- };
15
+ const otelResource = OtlpResource.make(options.resource);
61
16
  const scope = {
62
17
  name: options.resource.serviceName
63
18
  };
64
- let spanBuffer = [];
65
- const runExport = Effect.suspend(() => {
66
- if (spanBuffer.length === 0) {
67
- return Effect.void;
68
- }
69
- const spans = spanBuffer;
70
- spanBuffer = [];
71
- const data = {
72
- resourceSpans: [{
73
- resource: otelResource,
74
- scopeSpans: [{
75
- scope,
76
- spans
19
+ const exporter = yield* Exporter.make({
20
+ label: "OtlpTracer",
21
+ url: options.url,
22
+ headers: options.headers,
23
+ exportInterval: options.exportInterval ?? Duration.seconds(5),
24
+ maxBatchSize: options.maxBatchSize ?? 1000,
25
+ body(spans) {
26
+ const data = {
27
+ resourceSpans: [{
28
+ resource: otelResource,
29
+ scopeSpans: [{
30
+ scope,
31
+ spans
32
+ }]
77
33
  }]
78
- }]
79
- };
80
- return Effect.asVoid(client.execute(HttpClientRequest.post(options.url, {
81
- body: HttpBody.unsafeJson(data),
82
- headers
83
- })));
84
- }).pipe(Effect.catchAllCause(cause => Effect.logWarning("Failed to export spans", cause)), Effect.annotateLogs({
85
- package: "@effect/opentelemetry",
86
- module: "OtlpExporter"
87
- }));
88
- yield* Scope.addFinalizer(exporterScope, runExport);
89
- yield* Effect.sleep(exportInterval).pipe(Effect.zipRight(runExport), Effect.forever, Effect.forkScoped, Effect.interruptible);
90
- const runFork = yield* FiberSet.makeRuntime().pipe(Effect.interruptible);
91
- const addSpan = span => {
92
- spanBuffer.push(makeOtlpSpan(span));
93
- if (spanBuffer.length >= maxBatchSize) {
94
- runFork(runExport);
34
+ };
35
+ return data;
95
36
  }
96
- };
37
+ });
97
38
  return Tracer.make({
98
39
  span(name, parent, context, links, startTime, kind) {
99
40
  return makeSpan({
@@ -108,12 +49,17 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
108
49
  links,
109
50
  sampled: true,
110
51
  kind,
111
- export: addSpan
52
+ export(span) {
53
+ exporter.push(makeOtlpSpan(span));
54
+ }
112
55
  });
113
56
  },
114
- context(f, _fiber) {
115
- return f();
116
- }
57
+ context: options.context ? function (f, fiber) {
58
+ if (fiber.currentSpan === undefined) {
59
+ return f();
60
+ }
61
+ return options.context(f, fiber.currentSpan);
62
+ } : defaultContext
117
63
  });
118
64
  });
119
65
  /**
@@ -121,6 +67,10 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
121
67
  * @category Layers
122
68
  */
123
69
  export const layer = options => Layer.unwrapScoped(Effect.map(make(options), Layer.setTracer));
70
+ // internal
71
+ function defaultContext(f, _) {
72
+ return f();
73
+ }
124
74
  const SpanProto = {
125
75
  _tag: "Span",
126
76
  end(endTime, exit) {
@@ -178,10 +128,10 @@ const makeOtlpSpan = self => {
178
128
  const errors = Cause.prettyErrors(status.exit.cause);
179
129
  const firstError = errors[0];
180
130
  otelStatus = {
181
- code: StatusCode.Error,
182
- message: firstError && firstError.message
131
+ code: StatusCode.Error
183
132
  };
184
- for (const error of errors) {
133
+ if (firstError) {
134
+ otelStatus.message = firstError.message;
185
135
  events.push({
186
136
  name: "exception",
187
137
  timeUnixNano: String(status.endTime),
@@ -189,17 +139,19 @@ const makeOtlpSpan = self => {
189
139
  attributes: [{
190
140
  "key": "exception.type",
191
141
  "value": {
192
- "stringValue": error.name
142
+ "stringValue": firstError.name
193
143
  }
194
144
  }, {
195
145
  "key": "exception.message",
196
146
  "value": {
197
- "stringValue": error.message
147
+ "stringValue": firstError.message
198
148
  }
199
149
  }, {
200
150
  "key": "exception.stacktrace",
201
151
  "value": {
202
- "stringValue": error.stack ?? ""
152
+ "stringValue": Cause.pretty(status.exit.cause, {
153
+ renderErrorCause: true
154
+ })
203
155
  }
204
156
  }]
205
157
  });
@@ -227,42 +179,6 @@ const makeOtlpSpan = self => {
227
179
  droppedLinksCount: 0
228
180
  };
229
181
  };
230
- const unknownToAttributeValue = value => {
231
- switch (typeof value) {
232
- case "string":
233
- return {
234
- stringValue: value
235
- };
236
- case "bigint":
237
- return {
238
- intValue: Number(value)
239
- };
240
- case "number":
241
- return Number.isInteger(value) ? {
242
- intValue: value
243
- } : {
244
- doubleValue: value
245
- };
246
- case "boolean":
247
- return {
248
- boolValue: value
249
- };
250
- default:
251
- return {
252
- stringValue: Inspectable.toStringUnknown(value)
253
- };
254
- }
255
- };
256
- const entriesToAttributes = entries => {
257
- const attributes = [];
258
- for (const [key, value] of entries) {
259
- attributes.push({
260
- key,
261
- value: unknownToAttributeValue(value)
262
- });
263
- }
264
- return attributes;
265
- };
266
182
  var StatusCode;
267
183
  (function (StatusCode) {
268
184
  StatusCode[StatusCode["Unset"] = 0] = "Unset";