@elasticdash/tracing 0.0.7 → 0.0.8
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.cjs +91 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +198 -198
- package/dist/index.d.ts +198 -198
- package/dist/index.mjs +83 -80
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -20,27 +20,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
ElasticDashAgent: () => ElasticDashAgent,
|
|
24
|
+
ElasticDashChain: () => ElasticDashChain,
|
|
25
|
+
ElasticDashEmbedding: () => ElasticDashEmbedding,
|
|
26
|
+
ElasticDashEvaluator: () => ElasticDashEvaluator,
|
|
27
|
+
ElasticDashEvent: () => ElasticDashEvent,
|
|
28
|
+
ElasticDashGeneration: () => ElasticDashGeneration,
|
|
29
|
+
ElasticDashGuardrail: () => ElasticDashGuardrail,
|
|
30
|
+
ElasticDashOtelSpanAttributes: () => import_core5.ElasticDashOtelSpanAttributes,
|
|
31
|
+
ElasticDashRetriever: () => ElasticDashRetriever,
|
|
32
|
+
ElasticDashSpan: () => ElasticDashSpan,
|
|
33
|
+
ElasticDashTool: () => ElasticDashTool,
|
|
34
34
|
createObservationAttributes: () => createObservationAttributes,
|
|
35
35
|
createTraceAttributes: () => createTraceAttributes,
|
|
36
36
|
createTraceId: () => createTraceId,
|
|
37
37
|
getActiveSpanId: () => getActiveSpanId,
|
|
38
38
|
getActiveTraceId: () => getActiveTraceId,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
getElasticDashTracer: () => getElasticDashTracer,
|
|
40
|
+
getElasticDashTracerProvider: () => getElasticDashTracerProvider,
|
|
41
41
|
observe: () => observe,
|
|
42
42
|
propagateAttributes: () => import_core4.propagateAttributes,
|
|
43
|
-
|
|
43
|
+
setElasticDashTracerProvider: () => setElasticDashTracerProvider,
|
|
44
44
|
startActiveObservation: () => startActiveObservation,
|
|
45
45
|
startObservation: () => startObservation,
|
|
46
46
|
updateActiveObservation: () => updateActiveObservation,
|
|
@@ -66,16 +66,16 @@ function createTraceAttributes({
|
|
|
66
66
|
public: isPublic
|
|
67
67
|
} = {}) {
|
|
68
68
|
const attributes = {
|
|
69
|
-
[import_core.
|
|
70
|
-
[import_core.
|
|
71
|
-
[import_core.
|
|
72
|
-
[import_core.
|
|
73
|
-
[import_core.
|
|
74
|
-
[import_core.
|
|
75
|
-
[import_core.
|
|
76
|
-
[import_core.
|
|
77
|
-
[import_core.
|
|
78
|
-
[import_core.
|
|
69
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_NAME]: name,
|
|
70
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_USER_ID]: userId,
|
|
71
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_SESSION_ID]: sessionId,
|
|
72
|
+
[import_core.ElasticDashOtelSpanAttributes.VERSION]: version,
|
|
73
|
+
[import_core.ElasticDashOtelSpanAttributes.RELEASE]: release,
|
|
74
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_INPUT]: _serialize(input),
|
|
75
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_OUTPUT]: _serialize(output),
|
|
76
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_TAGS]: tags,
|
|
77
|
+
[import_core.ElasticDashOtelSpanAttributes.ENVIRONMENT]: environment,
|
|
78
|
+
[import_core.ElasticDashOtelSpanAttributes.TRACE_PUBLIC]: isPublic,
|
|
79
79
|
..._flattenAndSerializeMetadata(metadata, "trace")
|
|
80
80
|
};
|
|
81
81
|
return Object.fromEntries(
|
|
@@ -98,20 +98,20 @@ function createObservationAttributes(type, attributes) {
|
|
|
98
98
|
prompt
|
|
99
99
|
} = attributes;
|
|
100
100
|
let otelAttributes = {
|
|
101
|
-
[import_core.
|
|
102
|
-
[import_core.
|
|
103
|
-
[import_core.
|
|
104
|
-
[import_core.
|
|
105
|
-
[import_core.
|
|
106
|
-
[import_core.
|
|
107
|
-
[import_core.
|
|
108
|
-
[import_core.
|
|
109
|
-
[import_core.
|
|
110
|
-
[import_core.
|
|
111
|
-
[import_core.
|
|
101
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_TYPE]: type,
|
|
102
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_LEVEL]: level,
|
|
103
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: statusMessage,
|
|
104
|
+
[import_core.ElasticDashOtelSpanAttributes.VERSION]: version,
|
|
105
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_INPUT]: _serialize(input),
|
|
106
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_OUTPUT]: _serialize(output),
|
|
107
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_MODEL]: model,
|
|
108
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_USAGE_DETAILS]: _serialize(usageDetails),
|
|
109
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_COST_DETAILS]: _serialize(costDetails),
|
|
110
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_COMPLETION_START_TIME]: _serialize(completionStartTime),
|
|
111
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_MODEL_PARAMETERS]: _serialize(modelParameters),
|
|
112
112
|
...prompt && !prompt.isFallback ? {
|
|
113
|
-
[import_core.
|
|
114
|
-
[import_core.
|
|
113
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_PROMPT_NAME]: prompt.name,
|
|
114
|
+
[import_core.ElasticDashOtelSpanAttributes.OBSERVATION_PROMPT_VERSION]: prompt.version
|
|
115
115
|
} : {},
|
|
116
116
|
..._flattenAndSerializeMetadata(metadata, "observation")
|
|
117
117
|
};
|
|
@@ -128,7 +128,7 @@ function _serialize(obj) {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
function _flattenAndSerializeMetadata(metadata, type) {
|
|
131
|
-
const prefix = type === "observation" ? import_core.
|
|
131
|
+
const prefix = type === "observation" ? import_core.ElasticDashOtelSpanAttributes.OBSERVATION_METADATA : import_core.ElasticDashOtelSpanAttributes.TRACE_METADATA;
|
|
132
132
|
const metadataAttributes = {};
|
|
133
133
|
if (metadata === void 0 || metadata === null) {
|
|
134
134
|
return metadataAttributes;
|
|
@@ -187,23 +187,23 @@ function getGlobalState() {
|
|
|
187
187
|
return initialState;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function setElasticDashTracerProvider(provider) {
|
|
191
191
|
getGlobalState().isolatedTracerProvider = provider;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function getElasticDashTracerProvider() {
|
|
194
194
|
const { isolatedTracerProvider } = getGlobalState();
|
|
195
195
|
if (isolatedTracerProvider) return isolatedTracerProvider;
|
|
196
196
|
return import_api.trace.getTracerProvider();
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return
|
|
198
|
+
function getElasticDashTracer() {
|
|
199
|
+
return getElasticDashTracerProvider().getTracer(
|
|
200
200
|
import_core2.ELASTICDASH_TRACER_NAME,
|
|
201
201
|
import_core2.ELASTICDASH_SDK_VERSION
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
// src/spanWrapper.ts
|
|
206
|
-
var
|
|
206
|
+
var ElasticDashBaseObservation = class {
|
|
207
207
|
constructor(params) {
|
|
208
208
|
this.otelSpan = params.otelSpan;
|
|
209
209
|
this.id = params.otelSpan.spanContext().spanId;
|
|
@@ -217,7 +217,7 @@ var LangfuseBaseObservation = class {
|
|
|
217
217
|
}
|
|
218
218
|
/** Gets the ElasticDash OpenTelemetry tracer instance */
|
|
219
219
|
get tracer() {
|
|
220
|
-
return
|
|
220
|
+
return getElasticDashTracer();
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
223
|
* Ends the observation, marking it as complete.
|
|
@@ -248,7 +248,7 @@ var LangfuseBaseObservation = class {
|
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
|
-
var
|
|
251
|
+
var ElasticDashSpan = class extends ElasticDashBaseObservation {
|
|
252
252
|
constructor(params) {
|
|
253
253
|
super({ ...params, type: "span" });
|
|
254
254
|
}
|
|
@@ -272,7 +272,7 @@ var LangfuseSpan = class extends LangfuseBaseObservation {
|
|
|
272
272
|
return this;
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
|
-
var
|
|
275
|
+
var ElasticDashAgent = class extends ElasticDashBaseObservation {
|
|
276
276
|
constructor(params) {
|
|
277
277
|
super({ ...params, type: "agent" });
|
|
278
278
|
}
|
|
@@ -304,7 +304,7 @@ var LangfuseAgent = class extends LangfuseBaseObservation {
|
|
|
304
304
|
return this;
|
|
305
305
|
}
|
|
306
306
|
};
|
|
307
|
-
var
|
|
307
|
+
var ElasticDashTool = class extends ElasticDashBaseObservation {
|
|
308
308
|
constructor(params) {
|
|
309
309
|
super({ ...params, type: "tool" });
|
|
310
310
|
}
|
|
@@ -336,7 +336,7 @@ var LangfuseTool = class extends LangfuseBaseObservation {
|
|
|
336
336
|
return this;
|
|
337
337
|
}
|
|
338
338
|
};
|
|
339
|
-
var
|
|
339
|
+
var ElasticDashChain = class extends ElasticDashBaseObservation {
|
|
340
340
|
constructor(params) {
|
|
341
341
|
super({ ...params, type: "chain" });
|
|
342
342
|
}
|
|
@@ -368,7 +368,7 @@ var LangfuseChain = class extends LangfuseBaseObservation {
|
|
|
368
368
|
return this;
|
|
369
369
|
}
|
|
370
370
|
};
|
|
371
|
-
var
|
|
371
|
+
var ElasticDashRetriever = class extends ElasticDashBaseObservation {
|
|
372
372
|
constructor(params) {
|
|
373
373
|
super({ ...params, type: "retriever" });
|
|
374
374
|
}
|
|
@@ -383,7 +383,7 @@ var LangfuseRetriever = class extends LangfuseBaseObservation {
|
|
|
383
383
|
return this;
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
|
-
var
|
|
386
|
+
var ElasticDashEvaluator = class extends ElasticDashBaseObservation {
|
|
387
387
|
constructor(params) {
|
|
388
388
|
super({ ...params, type: "evaluator" });
|
|
389
389
|
}
|
|
@@ -398,7 +398,7 @@ var LangfuseEvaluator = class extends LangfuseBaseObservation {
|
|
|
398
398
|
return this;
|
|
399
399
|
}
|
|
400
400
|
};
|
|
401
|
-
var
|
|
401
|
+
var ElasticDashGuardrail = class extends ElasticDashBaseObservation {
|
|
402
402
|
constructor(params) {
|
|
403
403
|
super({ ...params, type: "guardrail" });
|
|
404
404
|
}
|
|
@@ -413,7 +413,7 @@ var LangfuseGuardrail = class extends LangfuseBaseObservation {
|
|
|
413
413
|
return this;
|
|
414
414
|
}
|
|
415
415
|
};
|
|
416
|
-
var
|
|
416
|
+
var ElasticDashGeneration = class extends ElasticDashBaseObservation {
|
|
417
417
|
constructor(params) {
|
|
418
418
|
super({ ...params, type: "generation" });
|
|
419
419
|
}
|
|
@@ -422,7 +422,7 @@ var LangfuseGeneration = class extends LangfuseBaseObservation {
|
|
|
422
422
|
return this;
|
|
423
423
|
}
|
|
424
424
|
};
|
|
425
|
-
var
|
|
425
|
+
var ElasticDashEmbedding = class extends ElasticDashBaseObservation {
|
|
426
426
|
constructor(params) {
|
|
427
427
|
super({ ...params, type: "embedding" });
|
|
428
428
|
}
|
|
@@ -437,7 +437,7 @@ var LangfuseEmbedding = class extends LangfuseBaseObservation {
|
|
|
437
437
|
return this;
|
|
438
438
|
}
|
|
439
439
|
};
|
|
440
|
-
var
|
|
440
|
+
var ElasticDashEvent = class extends ElasticDashBaseObservation {
|
|
441
441
|
constructor(params) {
|
|
442
442
|
super({ ...params, type: "event" });
|
|
443
443
|
this.otelSpan.end(params.timestamp);
|
|
@@ -448,7 +448,7 @@ var LangfuseEvent = class extends LangfuseBaseObservation {
|
|
|
448
448
|
var import_core4 = require("@elasticdash/core");
|
|
449
449
|
var import_core5 = require("@elasticdash/core");
|
|
450
450
|
function createOtelSpan(params) {
|
|
451
|
-
return
|
|
451
|
+
return getElasticDashTracer().startSpan(
|
|
452
452
|
params.name,
|
|
453
453
|
{ startTime: params.startTime },
|
|
454
454
|
createParentContext(params.parentSpanContext)
|
|
@@ -487,48 +487,48 @@ function startObservation(name, attributes, options) {
|
|
|
487
487
|
});
|
|
488
488
|
switch (asType) {
|
|
489
489
|
case "generation":
|
|
490
|
-
return new
|
|
490
|
+
return new ElasticDashGeneration({
|
|
491
491
|
otelSpan,
|
|
492
492
|
attributes
|
|
493
493
|
});
|
|
494
494
|
case "embedding":
|
|
495
|
-
return new
|
|
495
|
+
return new ElasticDashEmbedding({
|
|
496
496
|
otelSpan,
|
|
497
497
|
attributes
|
|
498
498
|
});
|
|
499
499
|
case "agent":
|
|
500
|
-
return new
|
|
500
|
+
return new ElasticDashAgent({
|
|
501
501
|
otelSpan,
|
|
502
502
|
attributes
|
|
503
503
|
});
|
|
504
504
|
case "tool":
|
|
505
|
-
return new
|
|
505
|
+
return new ElasticDashTool({
|
|
506
506
|
otelSpan,
|
|
507
507
|
attributes
|
|
508
508
|
});
|
|
509
509
|
case "chain":
|
|
510
|
-
return new
|
|
510
|
+
return new ElasticDashChain({
|
|
511
511
|
otelSpan,
|
|
512
512
|
attributes
|
|
513
513
|
});
|
|
514
514
|
case "retriever":
|
|
515
|
-
return new
|
|
515
|
+
return new ElasticDashRetriever({
|
|
516
516
|
otelSpan,
|
|
517
517
|
attributes
|
|
518
518
|
});
|
|
519
519
|
case "evaluator":
|
|
520
|
-
return new
|
|
520
|
+
return new ElasticDashEvaluator({
|
|
521
521
|
otelSpan,
|
|
522
522
|
attributes
|
|
523
523
|
});
|
|
524
524
|
case "guardrail":
|
|
525
|
-
return new
|
|
525
|
+
return new ElasticDashGuardrail({
|
|
526
526
|
otelSpan,
|
|
527
527
|
attributes
|
|
528
528
|
});
|
|
529
529
|
case "event": {
|
|
530
530
|
const timestamp = (_a = observationOptions == null ? void 0 : observationOptions.startTime) != null ? _a : /* @__PURE__ */ new Date();
|
|
531
|
-
return new
|
|
531
|
+
return new ElasticDashEvent({
|
|
532
532
|
otelSpan,
|
|
533
533
|
attributes,
|
|
534
534
|
timestamp
|
|
@@ -536,7 +536,7 @@ function startObservation(name, attributes, options) {
|
|
|
536
536
|
}
|
|
537
537
|
case "span":
|
|
538
538
|
default:
|
|
539
|
-
return new
|
|
539
|
+
return new ElasticDashSpan({
|
|
540
540
|
otelSpan,
|
|
541
541
|
attributes
|
|
542
542
|
});
|
|
@@ -545,7 +545,7 @@ function startObservation(name, attributes, options) {
|
|
|
545
545
|
function startActiveObservation(name, fn, options) {
|
|
546
546
|
var _a;
|
|
547
547
|
const { asType = "span", ...observationOptions } = options || {};
|
|
548
|
-
return
|
|
548
|
+
return getElasticDashTracer().startActiveSpan(
|
|
549
549
|
name,
|
|
550
550
|
{ startTime: observationOptions == null ? void 0 : observationOptions.startTime },
|
|
551
551
|
(_a = createParentContext(observationOptions == null ? void 0 : observationOptions.parentSpanContext)) != null ? _a : import_api2.context.active(),
|
|
@@ -555,48 +555,48 @@ function startActiveObservation(name, fn, options) {
|
|
|
555
555
|
let observation;
|
|
556
556
|
switch (asType) {
|
|
557
557
|
case "generation":
|
|
558
|
-
observation = new
|
|
558
|
+
observation = new ElasticDashGeneration({
|
|
559
559
|
otelSpan: span
|
|
560
560
|
});
|
|
561
561
|
break;
|
|
562
562
|
case "embedding":
|
|
563
|
-
observation = new
|
|
563
|
+
observation = new ElasticDashEmbedding({
|
|
564
564
|
otelSpan: span
|
|
565
565
|
});
|
|
566
566
|
break;
|
|
567
567
|
case "agent":
|
|
568
|
-
observation = new
|
|
568
|
+
observation = new ElasticDashAgent({
|
|
569
569
|
otelSpan: span
|
|
570
570
|
});
|
|
571
571
|
break;
|
|
572
572
|
case "tool":
|
|
573
|
-
observation = new
|
|
573
|
+
observation = new ElasticDashTool({
|
|
574
574
|
otelSpan: span
|
|
575
575
|
});
|
|
576
576
|
break;
|
|
577
577
|
case "chain":
|
|
578
|
-
observation = new
|
|
578
|
+
observation = new ElasticDashChain({
|
|
579
579
|
otelSpan: span
|
|
580
580
|
});
|
|
581
581
|
break;
|
|
582
582
|
case "retriever":
|
|
583
|
-
observation = new
|
|
583
|
+
observation = new ElasticDashRetriever({
|
|
584
584
|
otelSpan: span
|
|
585
585
|
});
|
|
586
586
|
break;
|
|
587
587
|
case "evaluator":
|
|
588
|
-
observation = new
|
|
588
|
+
observation = new ElasticDashEvaluator({
|
|
589
589
|
otelSpan: span
|
|
590
590
|
});
|
|
591
591
|
break;
|
|
592
592
|
case "guardrail":
|
|
593
|
-
observation = new
|
|
593
|
+
observation = new ElasticDashGuardrail({
|
|
594
594
|
otelSpan: span
|
|
595
595
|
});
|
|
596
596
|
break;
|
|
597
597
|
case "event": {
|
|
598
598
|
const timestamp = (_a2 = observationOptions == null ? void 0 : observationOptions.startTime) != null ? _a2 : /* @__PURE__ */ new Date();
|
|
599
|
-
observation = new
|
|
599
|
+
observation = new ElasticDashEvent({
|
|
600
600
|
otelSpan: span,
|
|
601
601
|
timestamp
|
|
602
602
|
});
|
|
@@ -604,7 +604,7 @@ function startActiveObservation(name, fn, options) {
|
|
|
604
604
|
}
|
|
605
605
|
case "span":
|
|
606
606
|
default:
|
|
607
|
-
observation = new
|
|
607
|
+
observation = new ElasticDashSpan({
|
|
608
608
|
otelSpan: span
|
|
609
609
|
});
|
|
610
610
|
}
|
|
@@ -658,7 +658,7 @@ function updateActiveObservation(attributes, options) {
|
|
|
658
658
|
attributes
|
|
659
659
|
);
|
|
660
660
|
if (!(options == null ? void 0 : options.asType)) {
|
|
661
|
-
otelAttributes[import_core3.
|
|
661
|
+
otelAttributes[import_core3.ElasticDashOtelSpanAttributes.OBSERVATION_TYPE] = void 0;
|
|
662
662
|
}
|
|
663
663
|
span.setAttributes(otelAttributes);
|
|
664
664
|
}
|
|
@@ -771,27 +771,27 @@ function getActiveSpanId() {
|
|
|
771
771
|
}
|
|
772
772
|
// Annotate the CommonJS export names for ESM import in node:
|
|
773
773
|
0 && (module.exports = {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
774
|
+
ElasticDashAgent,
|
|
775
|
+
ElasticDashChain,
|
|
776
|
+
ElasticDashEmbedding,
|
|
777
|
+
ElasticDashEvaluator,
|
|
778
|
+
ElasticDashEvent,
|
|
779
|
+
ElasticDashGeneration,
|
|
780
|
+
ElasticDashGuardrail,
|
|
781
|
+
ElasticDashOtelSpanAttributes,
|
|
782
|
+
ElasticDashRetriever,
|
|
783
|
+
ElasticDashSpan,
|
|
784
|
+
ElasticDashTool,
|
|
785
785
|
createObservationAttributes,
|
|
786
786
|
createTraceAttributes,
|
|
787
787
|
createTraceId,
|
|
788
788
|
getActiveSpanId,
|
|
789
789
|
getActiveTraceId,
|
|
790
|
-
|
|
791
|
-
|
|
790
|
+
getElasticDashTracer,
|
|
791
|
+
getElasticDashTracerProvider,
|
|
792
792
|
observe,
|
|
793
793
|
propagateAttributes,
|
|
794
|
-
|
|
794
|
+
setElasticDashTracerProvider,
|
|
795
795
|
startActiveObservation,
|
|
796
796
|
startObservation,
|
|
797
797
|
updateActiveObservation,
|