@paid-ai/paid-node 0.5.0-alpha3 → 0.5.0
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 +118 -36
- package/dist/cjs/Client.d.ts +35 -3
- package/dist/cjs/Client.js +57 -19
- package/dist/cjs/api/errors/InternalServerError.d.ts +9 -0
- package/dist/cjs/api/errors/InternalServerError.js +52 -0
- package/dist/cjs/api/errors/index.d.ts +1 -0
- package/dist/cjs/api/errors/index.js +1 -0
- package/dist/cjs/api/index.d.ts +1 -1
- package/dist/cjs/api/index.js +1 -1
- package/dist/cjs/api/resources/agents/client/Client.d.ts +16 -0
- package/dist/cjs/api/resources/agents/client/Client.js +16 -0
- package/dist/cjs/api/resources/customers/client/Client.d.ts +38 -0
- package/dist/cjs/api/resources/customers/client/Client.js +164 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomerCreate.d.ts +2 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.d.ts +30 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.d.ts +30 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.js +5 -0
- package/dist/cjs/api/resources/customers/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/index.d.ts +8 -1
- package/dist/cjs/api/resources/index.js +9 -2
- package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +2 -0
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +0 -2
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +0 -2
- package/dist/cjs/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.ts +0 -2
- package/dist/cjs/api/resources/plans/client/Client.d.ts +75 -0
- package/dist/cjs/api/resources/plans/client/Client.js +272 -0
- package/dist/cjs/api/resources/plans/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/client/index.js +17 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansGetUsageRequest.d.ts +35 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansGetUsageRequest.js +5 -0
- package/dist/cjs/api/resources/plans/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/plans/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/index.js +17 -0
- package/dist/cjs/api/resources/products/client/Client.d.ts +109 -0
- package/dist/cjs/api/resources/products/client/Client.js +470 -0
- package/dist/cjs/api/resources/products/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/products/client/index.js +17 -0
- package/dist/cjs/api/resources/products/client/requests/ProductCreate.d.ts +29 -0
- package/dist/cjs/api/resources/products/client/requests/ProductCreate.js +14 -0
- package/dist/cjs/api/resources/products/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/products/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/products/index.d.ts +1 -0
- package/dist/cjs/api/resources/products/index.js +17 -0
- package/dist/cjs/api/resources/traces/client/Client.d.ts +52 -0
- package/dist/cjs/api/resources/traces/client/Client.js +166 -0
- package/dist/cjs/api/resources/traces/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/traces/client/index.js +17 -0
- package/dist/cjs/api/resources/traces/client/requests/GetTracesRequest.d.ts +50 -0
- package/dist/cjs/api/resources/traces/client/requests/GetTracesRequest.js +5 -0
- package/dist/cjs/api/resources/traces/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/traces/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/traces/index.d.ts +1 -0
- package/dist/cjs/api/resources/traces/index.js +17 -0
- package/dist/cjs/api/resources/usage/client/Client.d.ts +47 -0
- package/dist/cjs/api/resources/usage/client/Client.js +146 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageCheckUsageRequest.d.ts +28 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageCheckUsageRequest.js +5 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +29 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.js +5 -0
- package/dist/cjs/api/resources/usage/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/usage/index.d.ts +1 -0
- package/dist/cjs/api/resources/usage/index.js +1 -0
- package/dist/cjs/api/resources/usage/types/UsageCheckUsageResponse.d.ts +17 -0
- package/dist/cjs/api/resources/usage/types/UsageCheckUsageResponse.js +5 -0
- package/dist/cjs/api/resources/usage/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/usage/types/index.js +17 -0
- package/dist/cjs/api/types/CostAmount.d.ts +12 -0
- package/dist/cjs/api/types/CostAmount.js +5 -0
- package/dist/cjs/api/types/CostTrace.d.ts +22 -0
- package/dist/cjs/api/types/CostTrace.js +5 -0
- package/dist/cjs/api/types/CostTracesResponse.d.ts +11 -0
- package/dist/cjs/api/types/CostTracesResponse.js +5 -0
- package/dist/cjs/api/types/Customer.d.ts +2 -0
- package/dist/cjs/api/types/CustomerUpdate.d.ts +2 -0
- package/dist/cjs/api/types/OrderLineAttributeCreateOne.d.ts +4 -0
- package/dist/cjs/api/types/OrderLineAttributeCreateOne.js +5 -0
- package/dist/cjs/api/types/OrderLineCreate.d.ts +10 -4
- package/dist/cjs/api/types/PaginationMeta.d.ts +28 -0
- package/dist/cjs/api/types/PaginationMeta.js +5 -0
- package/dist/cjs/api/types/Plan.d.ts +58 -0
- package/dist/cjs/api/types/Plan.js +5 -0
- package/dist/cjs/api/types/PlanGroup.d.ts +23 -0
- package/dist/cjs/api/types/PlanGroup.js +5 -0
- package/dist/cjs/api/types/Product.d.ts +36 -0
- package/dist/cjs/api/types/Product.js +14 -0
- package/dist/cjs/api/types/ProductUpdate.d.ts +23 -0
- package/dist/cjs/api/types/ProductUpdate.js +14 -0
- package/dist/cjs/api/types/Signal.d.ts +7 -2
- package/dist/cjs/api/types/SignalV2.d.ts +22 -0
- package/dist/cjs/api/types/SignalV2.js +5 -0
- package/dist/cjs/api/types/Trace.d.ts +26 -0
- package/dist/cjs/api/types/Trace.js +5 -0
- package/dist/cjs/api/types/TracesResponse.d.ts +11 -0
- package/dist/cjs/api/types/TracesResponse.js +5 -0
- package/dist/cjs/api/types/UsagePaginationMeta.d.ts +16 -0
- package/dist/cjs/api/types/UsagePaginationMeta.js +5 -0
- package/dist/cjs/api/types/UsageSummariesResponse.d.ts +11 -0
- package/dist/cjs/api/types/UsageSummariesResponse.js +5 -0
- package/dist/cjs/api/types/UsageSummary.d.ts +58 -0
- package/dist/cjs/api/types/UsageSummary.js +5 -0
- package/dist/cjs/api/types/index.d.ts +15 -1
- package/dist/cjs/api/types/index.js +15 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/tracing/autoInstrumentation.d.ts +10 -0
- package/dist/cjs/tracing/autoInstrumentation.js +57 -0
- package/dist/cjs/tracing/index.d.ts +4 -0
- package/dist/cjs/tracing/index.js +12 -0
- package/dist/cjs/tracing/signal.d.ts +18 -1
- package/dist/cjs/tracing/signal.js +29 -13
- package/dist/cjs/tracing/spanProcessor.d.ts +10 -0
- package/dist/cjs/tracing/spanProcessor.js +82 -0
- package/dist/cjs/tracing/tracing.d.ts +12 -6
- package/dist/cjs/tracing/tracing.js +65 -58
- package/dist/cjs/tracing/tracingContext.d.ts +8 -0
- package/dist/cjs/tracing/tracingContext.js +28 -0
- package/dist/cjs/tracing/wrappers/anthropicWrapper.js +11 -7
- package/dist/cjs/tracing/wrappers/langchainCallback.js +11 -7
- package/dist/cjs/tracing/wrappers/mistralWrapper.js +11 -7
- package/dist/cjs/tracing/wrappers/openAiWrapper.js +24 -23
- package/dist/cjs/tracing/wrappers/vercelAIWrapper.js +68 -43
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.d.mts +35 -3
- package/dist/esm/Client.mjs +54 -16
- package/dist/esm/api/errors/InternalServerError.d.mts +9 -0
- package/dist/esm/api/errors/InternalServerError.mjs +15 -0
- package/dist/esm/api/errors/index.d.mts +1 -0
- package/dist/esm/api/errors/index.mjs +1 -0
- package/dist/esm/api/index.d.mts +1 -1
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/resources/agents/client/Client.d.mts +16 -0
- package/dist/esm/api/resources/agents/client/Client.mjs +16 -0
- package/dist/esm/api/resources/customers/client/Client.d.mts +38 -0
- package/dist/esm/api/resources/customers/client/Client.mjs +164 -0
- package/dist/esm/api/resources/customers/client/requests/CustomerCreate.d.mts +2 -0
- package/dist/esm/api/resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.d.mts +30 -0
- package/dist/esm/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.d.mts +30 -0
- package/dist/esm/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.mjs +4 -0
- package/dist/esm/api/resources/customers/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/index.d.mts +8 -1
- package/dist/esm/api/resources/index.mjs +8 -1
- package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +2 -0
- package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +0 -2
- package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +0 -2
- package/dist/esm/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.mts +0 -2
- package/dist/esm/api/resources/plans/client/Client.d.mts +75 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +232 -0
- package/dist/esm/api/resources/plans/client/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/client/index.mjs +1 -0
- package/dist/esm/api/resources/plans/client/requests/PlansGetUsageRequest.d.mts +35 -0
- package/dist/esm/api/resources/plans/client/requests/PlansGetUsageRequest.mjs +4 -0
- package/dist/esm/api/resources/plans/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/plans/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/index.mjs +1 -0
- package/dist/esm/api/resources/products/client/Client.d.mts +109 -0
- package/dist/esm/api/resources/products/client/Client.mjs +430 -0
- package/dist/esm/api/resources/products/client/index.d.mts +1 -0
- package/dist/esm/api/resources/products/client/index.mjs +1 -0
- package/dist/esm/api/resources/products/client/requests/ProductCreate.d.mts +29 -0
- package/dist/esm/api/resources/products/client/requests/ProductCreate.mjs +11 -0
- package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/products/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/products/index.d.mts +1 -0
- package/dist/esm/api/resources/products/index.mjs +1 -0
- package/dist/esm/api/resources/traces/client/Client.d.mts +52 -0
- package/dist/esm/api/resources/traces/client/Client.mjs +126 -0
- package/dist/esm/api/resources/traces/client/index.d.mts +1 -0
- package/dist/esm/api/resources/traces/client/index.mjs +1 -0
- package/dist/esm/api/resources/traces/client/requests/GetTracesRequest.d.mts +50 -0
- package/dist/esm/api/resources/traces/client/requests/GetTracesRequest.mjs +4 -0
- package/dist/esm/api/resources/traces/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/traces/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/traces/index.d.mts +1 -0
- package/dist/esm/api/resources/traces/index.mjs +1 -0
- package/dist/esm/api/resources/usage/client/Client.d.mts +47 -0
- package/dist/esm/api/resources/usage/client/Client.mjs +146 -0
- package/dist/esm/api/resources/usage/client/requests/UsageCheckUsageRequest.d.mts +28 -0
- package/dist/esm/api/resources/usage/client/requests/UsageCheckUsageRequest.mjs +4 -0
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +29 -0
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.mjs +4 -0
- package/dist/esm/api/resources/usage/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/usage/index.d.mts +1 -0
- package/dist/esm/api/resources/usage/index.mjs +1 -0
- package/dist/esm/api/resources/usage/types/UsageCheckUsageResponse.d.mts +17 -0
- package/dist/esm/api/resources/usage/types/UsageCheckUsageResponse.mjs +4 -0
- package/dist/esm/api/resources/usage/types/index.d.mts +1 -0
- package/dist/esm/api/resources/usage/types/index.mjs +1 -0
- package/dist/esm/api/types/CostAmount.d.mts +12 -0
- package/dist/esm/api/types/CostAmount.mjs +4 -0
- package/dist/esm/api/types/CostTrace.d.mts +22 -0
- package/dist/esm/api/types/CostTrace.mjs +4 -0
- package/dist/esm/api/types/CostTracesResponse.d.mts +11 -0
- package/dist/esm/api/types/CostTracesResponse.mjs +4 -0
- package/dist/esm/api/types/Customer.d.mts +2 -0
- package/dist/esm/api/types/CustomerUpdate.d.mts +2 -0
- package/dist/esm/api/types/OrderLineAttributeCreateOne.d.mts +4 -0
- package/dist/esm/api/types/OrderLineAttributeCreateOne.mjs +4 -0
- package/dist/esm/api/types/OrderLineCreate.d.mts +10 -4
- package/dist/esm/api/types/PaginationMeta.d.mts +28 -0
- package/dist/esm/api/types/PaginationMeta.mjs +4 -0
- package/dist/esm/api/types/Plan.d.mts +58 -0
- package/dist/esm/api/types/Plan.mjs +4 -0
- package/dist/esm/api/types/PlanGroup.d.mts +23 -0
- package/dist/esm/api/types/PlanGroup.mjs +4 -0
- package/dist/esm/api/types/Product.d.mts +36 -0
- package/dist/esm/api/types/Product.mjs +11 -0
- package/dist/esm/api/types/ProductUpdate.d.mts +23 -0
- package/dist/esm/api/types/ProductUpdate.mjs +11 -0
- package/dist/esm/api/types/Signal.d.mts +7 -2
- package/dist/esm/api/types/SignalV2.d.mts +22 -0
- package/dist/esm/api/types/SignalV2.mjs +4 -0
- package/dist/esm/api/types/Trace.d.mts +26 -0
- package/dist/esm/api/types/Trace.mjs +4 -0
- package/dist/esm/api/types/TracesResponse.d.mts +11 -0
- package/dist/esm/api/types/TracesResponse.mjs +4 -0
- package/dist/esm/api/types/UsagePaginationMeta.d.mts +16 -0
- package/dist/esm/api/types/UsagePaginationMeta.mjs +4 -0
- package/dist/esm/api/types/UsageSummariesResponse.d.mts +11 -0
- package/dist/esm/api/types/UsageSummariesResponse.mjs +4 -0
- package/dist/esm/api/types/UsageSummary.d.mts +58 -0
- package/dist/esm/api/types/UsageSummary.mjs +4 -0
- package/dist/esm/api/types/index.d.mts +15 -1
- package/dist/esm/api/types/index.mjs +15 -1
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/tracing/autoInstrumentation.d.mts +10 -0
- package/dist/esm/tracing/autoInstrumentation.mjs +54 -0
- package/dist/esm/tracing/index.d.mts +4 -0
- package/dist/esm/tracing/index.mjs +4 -0
- package/dist/esm/tracing/signal.d.mts +18 -1
- package/dist/esm/tracing/signal.mjs +28 -12
- package/dist/esm/tracing/spanProcessor.d.mts +10 -0
- package/dist/esm/tracing/spanProcessor.mjs +78 -0
- package/dist/esm/tracing/tracing.d.mts +12 -6
- package/dist/esm/tracing/tracing.mjs +59 -52
- package/dist/esm/tracing/tracingContext.d.mts +8 -0
- package/dist/esm/tracing/tracingContext.mjs +23 -0
- package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +11 -7
- package/dist/esm/tracing/wrappers/langchainCallback.mjs +11 -7
- package/dist/esm/tracing/wrappers/mistralWrapper.mjs +11 -7
- package/dist/esm/tracing/wrappers/openAiWrapper.mjs +24 -23
- package/dist/esm/tracing/wrappers/vercelAIWrapper.mjs +68 -43
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +18 -10
- package/reference.md +1147 -153
- package/dist/cjs/api/types/OrderLineAttributeCreate.d.ts +0 -12
- package/dist/esm/api/types/OrderLineAttributeCreate.d.mts +0 -12
- /package/dist/cjs/api/{types/OrderLineAttributeCreate.js → resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.js} +0 -0
- /package/dist/esm/api/{types/OrderLineAttributeCreate.mjs → resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.mjs} +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paidAutoInstrument = paidAutoInstrument;
|
|
4
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
5
|
+
const openinference_instrumentation_openai_1 = require("@arizeai/openinference-instrumentation-openai");
|
|
6
|
+
const instrumentation_bedrock_1 = require("@traceloop/instrumentation-bedrock");
|
|
7
|
+
const openinference_instrumentation_anthropic_1 = require("@arizeai/openinference-instrumentation-anthropic");
|
|
8
|
+
const tracing_1 = require("./tracing");
|
|
9
|
+
let IS_INITIALIZED = false;
|
|
10
|
+
const getInstrumentations = (tracerProvider) => {
|
|
11
|
+
const instrumentations = [
|
|
12
|
+
new openinference_instrumentation_openai_1.OpenAIInstrumentation({ tracerProvider }),
|
|
13
|
+
new openinference_instrumentation_anthropic_1.AnthropicInstrumentation({ tracerProvider }),
|
|
14
|
+
new instrumentation_bedrock_1.BedrockInstrumentation(),
|
|
15
|
+
];
|
|
16
|
+
return instrumentations;
|
|
17
|
+
};
|
|
18
|
+
const getManualInstrumentations = (tracerProvider, libraries) => {
|
|
19
|
+
const instrumentations = [];
|
|
20
|
+
if (libraries.openai) {
|
|
21
|
+
const openaiInstrumentation = new openinference_instrumentation_openai_1.OpenAIInstrumentation({ tracerProvider });
|
|
22
|
+
instrumentations.push(openaiInstrumentation);
|
|
23
|
+
openaiInstrumentation.manuallyInstrument(libraries.openai);
|
|
24
|
+
}
|
|
25
|
+
if (libraries.anthropic) {
|
|
26
|
+
const anthropicInstrumentation = new openinference_instrumentation_anthropic_1.AnthropicInstrumentation({ tracerProvider });
|
|
27
|
+
instrumentations.push(anthropicInstrumentation);
|
|
28
|
+
anthropicInstrumentation.manuallyInstrument(libraries.anthropic);
|
|
29
|
+
}
|
|
30
|
+
if (libraries.bedrock) {
|
|
31
|
+
const bedrockInstrumentation = new instrumentation_bedrock_1.BedrockInstrumentation();
|
|
32
|
+
instrumentations.push(bedrockInstrumentation);
|
|
33
|
+
bedrockInstrumentation.manuallyInstrument(libraries.bedrock);
|
|
34
|
+
}
|
|
35
|
+
return instrumentations;
|
|
36
|
+
};
|
|
37
|
+
function paidAutoInstrument(libraries) {
|
|
38
|
+
if (IS_INITIALIZED) {
|
|
39
|
+
tracing_1.logger.info("Auto instrumentation is already initialized");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
(0, tracing_1.initializeTracing)(); // try initializing tracing
|
|
43
|
+
const tracerProvider = (0, tracing_1.getPaidTracerProvider)();
|
|
44
|
+
if (!tracerProvider) {
|
|
45
|
+
tracing_1.logger.error("Could not get tracer provider, make sure you ran 'initializeTracing()' or check your environment variables");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const isManualInstrumentation = libraries && Object.keys(libraries).length > 0;
|
|
49
|
+
const instrumentations = isManualInstrumentation
|
|
50
|
+
? getManualInstrumentations(tracerProvider, libraries)
|
|
51
|
+
: getInstrumentations(tracerProvider);
|
|
52
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
53
|
+
instrumentations,
|
|
54
|
+
tracerProvider,
|
|
55
|
+
});
|
|
56
|
+
IS_INITIALIZED = true;
|
|
57
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { getPaidTracer, getPaidTracerProvider, initializeTracing, trace } from "./tracing.js";
|
|
2
|
+
import { paidAutoInstrument } from "./autoInstrumentation.js";
|
|
3
|
+
import { signal } from "./signal.js";
|
|
4
|
+
export { getPaidTracer, getPaidTracerProvider, initializeTracing, trace, signal, paidAutoInstrument };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paidAutoInstrument = exports.signal = exports.trace = exports.initializeTracing = exports.getPaidTracerProvider = exports.getPaidTracer = void 0;
|
|
4
|
+
const tracing_js_1 = require("./tracing.js");
|
|
5
|
+
Object.defineProperty(exports, "getPaidTracer", { enumerable: true, get: function () { return tracing_js_1.getPaidTracer; } });
|
|
6
|
+
Object.defineProperty(exports, "getPaidTracerProvider", { enumerable: true, get: function () { return tracing_js_1.getPaidTracerProvider; } });
|
|
7
|
+
Object.defineProperty(exports, "initializeTracing", { enumerable: true, get: function () { return tracing_js_1.initializeTracing; } });
|
|
8
|
+
Object.defineProperty(exports, "trace", { enumerable: true, get: function () { return tracing_js_1.trace; } });
|
|
9
|
+
const autoInstrumentation_js_1 = require("./autoInstrumentation.js");
|
|
10
|
+
Object.defineProperty(exports, "paidAutoInstrument", { enumerable: true, get: function () { return autoInstrumentation_js_1.paidAutoInstrument; } });
|
|
11
|
+
const signal_js_1 = require("./signal.js");
|
|
12
|
+
Object.defineProperty(exports, "signal", { enumerable: true, get: function () { return signal_js_1.signal; } });
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Sends Paid signal. Needs to be called as part of callback to trace().
|
|
3
|
+
* When enableCostTracing flag is on, signal is associated
|
|
4
|
+
* with cost traces from the same Paid.trace() context.
|
|
5
|
+
*
|
|
6
|
+
* @param eventName - The name of the signal.
|
|
7
|
+
* @param enableCostTracing - Whether to associate this signal with cost traces
|
|
8
|
+
* from the current Paid.trace() context (default: false)
|
|
9
|
+
* @param data - Optional additional data to include with the signal
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* When enableCostTracing is on, the signal will be associated with cost
|
|
13
|
+
* traces within the same Paid.trace() context.
|
|
14
|
+
* It is advised to only make one call to this function
|
|
15
|
+
* with enableCostTracing per Paid.trace() context.
|
|
16
|
+
* Otherwise, there will be multiple signals that refer to the same costs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function signal(eventName: string, enableCostTracing?: boolean, data?: Record<string, any>): void;
|
|
@@ -1,24 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.signal = signal;
|
|
4
4
|
const api_1 = require("@opentelemetry/api");
|
|
5
5
|
const tracing_js_1 = require("./tracing.js");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const tracingContext_js_1 = require("./tracingContext.js");
|
|
7
|
+
/**
|
|
8
|
+
* Sends Paid signal. Needs to be called as part of callback to trace().
|
|
9
|
+
* When enableCostTracing flag is on, signal is associated
|
|
10
|
+
* with cost traces from the same Paid.trace() context.
|
|
11
|
+
*
|
|
12
|
+
* @param eventName - The name of the signal.
|
|
13
|
+
* @param enableCostTracing - Whether to associate this signal with cost traces
|
|
14
|
+
* from the current Paid.trace() context (default: false)
|
|
15
|
+
* @param data - Optional additional data to include with the signal
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* When enableCostTracing is on, the signal will be associated with cost
|
|
19
|
+
* traces within the same Paid.trace() context.
|
|
20
|
+
* It is advised to only make one call to this function
|
|
21
|
+
* with enableCostTracing per Paid.trace() context.
|
|
22
|
+
* Otherwise, there will be multiple signals that refer to the same costs.
|
|
23
|
+
*/
|
|
24
|
+
function signal(eventName, enableCostTracing = false, data) {
|
|
25
|
+
const paidTracer = (0, tracing_js_1.getPaidTracer)();
|
|
26
|
+
const token = (0, tracing_js_1.getToken)();
|
|
27
|
+
const { externalCustomerId, externalProductId } = (0, tracingContext_js_1.getTracingContext)();
|
|
28
|
+
if (!token || !paidTracer) {
|
|
29
|
+
throw new Error(`Tracing is not initialized. Make sure you called 'initializeTracing()'`);
|
|
10
30
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const token = (0, tracing_js_1.getTokenStorage)();
|
|
14
|
-
if (!externalCustomerId || !externalAgentId || !token) {
|
|
15
|
-
throw new Error(`Missing some of: external_customer_id: ${externalCustomerId}, external_agent_id: ${externalAgentId}, or token. Make sure to call signal() within trace()`);
|
|
31
|
+
if (!externalCustomerId || !externalProductId) {
|
|
32
|
+
throw new Error(`Missing some of: external_customer_id: ${externalCustomerId}, external_product_id: ${externalProductId}, or token. Make sure to call signal() within trace()`);
|
|
16
33
|
}
|
|
17
|
-
|
|
34
|
+
paidTracer.startActiveSpan("trace.signal", (span) => {
|
|
18
35
|
try {
|
|
19
36
|
const attributes = {
|
|
20
37
|
external_customer_id: externalCustomerId,
|
|
21
|
-
external_agent_id:
|
|
38
|
+
external_agent_id: externalProductId,
|
|
22
39
|
event_name: eventName,
|
|
23
40
|
token: token,
|
|
24
41
|
};
|
|
@@ -37,7 +54,6 @@ function _signal(eventName, enableCostTracing, data) {
|
|
|
37
54
|
attributes["data"] = JSON.stringify(data);
|
|
38
55
|
}
|
|
39
56
|
span.setAttributes(attributes);
|
|
40
|
-
// Mark span as successful
|
|
41
57
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
42
58
|
}
|
|
43
59
|
catch (error) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "@opentelemetry/api";
|
|
2
|
+
import { SpanProcessor, Span } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
export declare class PaidSpanProcessor implements SpanProcessor {
|
|
4
|
+
private static readonly SPAN_NAME_PREFIX;
|
|
5
|
+
private static readonly PROMPT_ATTRIBUTES_SUBSTRINGS;
|
|
6
|
+
onStart(span: Span, _parentContext?: Context): void;
|
|
7
|
+
onEnd(): void;
|
|
8
|
+
shutdown(): Promise<void>;
|
|
9
|
+
forceFlush(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PaidSpanProcessor = void 0;
|
|
13
|
+
const tracingContext_js_1 = require("./tracingContext.js");
|
|
14
|
+
const tracing_js_1 = require("./tracing.js");
|
|
15
|
+
class PaidSpanProcessor {
|
|
16
|
+
onStart(span, _parentContext) {
|
|
17
|
+
const { name } = span;
|
|
18
|
+
const { storePrompt, externalCustomerId, externalProductId: externalAgentId } = (0, tracingContext_js_1.getTracingContext)();
|
|
19
|
+
if (!storePrompt) {
|
|
20
|
+
const originalSetAttribute = span.setAttribute;
|
|
21
|
+
span.setAttribute = function (key, value) {
|
|
22
|
+
const isPromptRelated = PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((substr) => key.includes(substr));
|
|
23
|
+
if (isPromptRelated)
|
|
24
|
+
return this;
|
|
25
|
+
return originalSetAttribute.call(this, key, value);
|
|
26
|
+
};
|
|
27
|
+
const originalSetAttributes = span.setAttributes;
|
|
28
|
+
span.setAttributes = function (attributes) {
|
|
29
|
+
const newAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {
|
|
30
|
+
const isPromptRelated = PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((substr) => key.includes(substr));
|
|
31
|
+
if (isPromptRelated)
|
|
32
|
+
return acc;
|
|
33
|
+
return Object.assign(Object.assign({}, acc), { [key]: value });
|
|
34
|
+
}, {});
|
|
35
|
+
return originalSetAttributes.call(this, newAttributes);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (name && !name.startsWith(PaidSpanProcessor.SPAN_NAME_PREFIX)) {
|
|
39
|
+
span.updateName(`${PaidSpanProcessor.SPAN_NAME_PREFIX}${name}`);
|
|
40
|
+
}
|
|
41
|
+
if (externalCustomerId) {
|
|
42
|
+
span.setAttribute("external_customer_id", externalCustomerId);
|
|
43
|
+
}
|
|
44
|
+
if (externalAgentId) {
|
|
45
|
+
span.setAttribute("external_agent_id", externalAgentId);
|
|
46
|
+
}
|
|
47
|
+
const token = (0, tracing_js_1.getToken)();
|
|
48
|
+
if (token) {
|
|
49
|
+
span.setAttribute("token", token);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
onEnd() {
|
|
53
|
+
// mutating this span object doesn't do anything
|
|
54
|
+
// so we achieve filtering within the onStart method by monkey patching
|
|
55
|
+
// setAttribute method
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
shutdown() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
forceFlush() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.PaidSpanProcessor = PaidSpanProcessor;
|
|
70
|
+
PaidSpanProcessor.SPAN_NAME_PREFIX = "paid.trace.";
|
|
71
|
+
PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS = [
|
|
72
|
+
"gen_ai.completion",
|
|
73
|
+
"gen_ai.request.messages",
|
|
74
|
+
"gen_ai.response.messages",
|
|
75
|
+
"llm.output_message",
|
|
76
|
+
"llm.input_message",
|
|
77
|
+
"llm.invocation_parameters",
|
|
78
|
+
"gen_ai.prompt",
|
|
79
|
+
"langchain.prompt",
|
|
80
|
+
"output.value",
|
|
81
|
+
"input.value",
|
|
82
|
+
];
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { Tracer } from "@opentelemetry/api";
|
|
2
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
1
3
|
import winston from "winston";
|
|
2
4
|
export declare const logger: winston.Logger;
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare function
|
|
8
|
-
|
|
5
|
+
export declare function getToken(): string | undefined;
|
|
6
|
+
export declare function getPaidTracerProvider(): NodeTracerProvider | undefined;
|
|
7
|
+
export declare function getPaidTracer(): Tracer | undefined;
|
|
8
|
+
export declare function initializeTracing(apiKey?: string, collectorEndpoint?: string): void;
|
|
9
|
+
export declare function trace<F extends (...args: any[]) => any>(options: {
|
|
10
|
+
externalCustomerId: string;
|
|
11
|
+
externalProductId?: string;
|
|
12
|
+
storePrompt?: boolean;
|
|
13
|
+
metadata?: any;
|
|
14
|
+
}, fn: F, ...args: Parameters<F>): Promise<ReturnType<F>>;
|
|
@@ -12,15 +12,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
exports.logger = void 0;
|
|
16
|
+
exports.getToken = getToken;
|
|
17
|
+
exports.getPaidTracerProvider = getPaidTracerProvider;
|
|
18
|
+
exports.getPaidTracer = getPaidTracer;
|
|
19
|
+
exports.initializeTracing = initializeTracing;
|
|
20
|
+
exports.trace = trace;
|
|
21
21
|
const api_1 = require("@opentelemetry/api");
|
|
22
|
-
const
|
|
22
|
+
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
23
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
23
24
|
const winston_1 = __importDefault(require("winston"));
|
|
25
|
+
const tracingContext_js_1 = require("./tracingContext.js");
|
|
26
|
+
const spanProcessor_js_1 = require("./spanProcessor.js");
|
|
24
27
|
exports.logger = winston_1.default.createLogger({
|
|
25
28
|
level: "silent", // Default to 'silent' to avoid logging unless set via environment variable
|
|
26
29
|
format: winston_1.default.format.simple(),
|
|
@@ -30,32 +33,21 @@ const logLevel = process.env.PAID_LOG_LEVEL;
|
|
|
30
33
|
if (logLevel) {
|
|
31
34
|
exports.logger.level = logLevel;
|
|
32
35
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
paidTracerProvider
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const getAgentIdStorage = () => agentIdStorage.getStore();
|
|
47
|
-
exports.getAgentIdStorage = getAgentIdStorage;
|
|
48
|
-
const getTokenStorage = () => tokenStorage.getStore();
|
|
49
|
-
exports.getTokenStorage = getTokenStorage;
|
|
50
|
-
let _token;
|
|
51
|
-
const setToken = (token) => {
|
|
52
|
-
_token = token;
|
|
53
|
-
};
|
|
54
|
-
const getToken = () => {
|
|
55
|
-
return _token;
|
|
56
|
-
};
|
|
36
|
+
const DEFAULT_COLLECTOR_ENDPOINT = process.env["PAID_OTEL_COLLECTOR_ENDPOINT"] || "https://collector.agentpaid.io:4318/v1/traces";
|
|
37
|
+
let paidApiToken = undefined;
|
|
38
|
+
function getToken() {
|
|
39
|
+
return paidApiToken;
|
|
40
|
+
}
|
|
41
|
+
let paidTracerProvider = undefined;
|
|
42
|
+
function getPaidTracerProvider() {
|
|
43
|
+
return paidTracerProvider;
|
|
44
|
+
}
|
|
45
|
+
let paidTracer = undefined;
|
|
46
|
+
function getPaidTracer() {
|
|
47
|
+
return paidTracer;
|
|
48
|
+
}
|
|
57
49
|
let _isShuttingDown = false;
|
|
58
|
-
|
|
50
|
+
const setupGracefulShutdown = (shuttable) => {
|
|
59
51
|
["SIGINT", "SIGTERM", "beforeExit", "uncaughtException", "unhandledRejection"].forEach((signal) => {
|
|
60
52
|
process.on(signal, () => {
|
|
61
53
|
if (_isShuttingDown) {
|
|
@@ -68,48 +60,63 @@ function setupGracefulShutdown(shuttable) {
|
|
|
68
60
|
.catch((error) => exports.logger.error(`Error shutting down Paid tracing SDK ${error}`));
|
|
69
61
|
});
|
|
70
62
|
});
|
|
71
|
-
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
};
|
|
64
|
+
function initializeTracing(apiKey, collectorEndpoint) {
|
|
65
|
+
const paidEnabled = (process.env.PAID_ENABLED || "true") !== "false";
|
|
66
|
+
if (!paidEnabled) {
|
|
67
|
+
exports.logger.info("Paid tracing is disabled via PAID_ENABLED environment variable");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const token = getToken();
|
|
71
|
+
if (!!token) {
|
|
72
|
+
exports.logger.info("Tracing is already initialized - skipping re-intialization");
|
|
73
|
+
return;
|
|
75
74
|
}
|
|
76
75
|
if (!apiKey) {
|
|
77
|
-
|
|
76
|
+
const envKey = process.env.PAID_API_KEY;
|
|
77
|
+
if (!envKey) {
|
|
78
|
+
exports.logger.error("API key must be provided via PAID_API_KEY environment variable");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
paidApiToken = envKey;
|
|
78
82
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
spanProcessor = new sdk_trace_base_1.BatchSpanProcessor(paidExporter);
|
|
82
|
-
paidTracerProvider = new sdk_trace_node_1.NodeTracerProvider({ spanProcessors: [spanProcessor] });
|
|
83
|
-
paidTracerProvider.register();
|
|
84
|
-
exports.paidTracer = paidTracerProvider.getTracer("paid.node");
|
|
83
|
+
else {
|
|
84
|
+
paidApiToken = apiKey;
|
|
85
85
|
}
|
|
86
|
+
const url = collectorEndpoint || DEFAULT_COLLECTOR_ENDPOINT;
|
|
87
|
+
const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({ url });
|
|
88
|
+
const spanProcessor = new sdk_trace_node_1.SimpleSpanProcessor(exporter);
|
|
89
|
+
paidTracerProvider = new sdk_trace_node_1.NodeTracerProvider({
|
|
90
|
+
spanProcessors: [spanProcessor, new spanProcessor_js_1.PaidSpanProcessor()],
|
|
91
|
+
});
|
|
92
|
+
paidTracerProvider.register();
|
|
93
|
+
paidTracer = paidTracerProvider.getTracer("paid.node");
|
|
86
94
|
setupGracefulShutdown(spanProcessor);
|
|
87
|
-
|
|
88
|
-
const collectorAddress = collectorEndpoint || COLLECTOR_ENDPOINT;
|
|
89
|
-
exports.logger.info(`Paid tracing SDK initialized with collector endpoint: ${collectorAddress}`);
|
|
95
|
+
exports.logger.info(`Paid tracing SDK initialized with collector endpoint: ${url}`);
|
|
90
96
|
}
|
|
91
|
-
function
|
|
97
|
+
function trace(options, fn, ...args) {
|
|
92
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
99
|
const token = getToken();
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
const tracer = getPaidTracer();
|
|
101
|
+
if (!token || !tracer) {
|
|
102
|
+
throw new Error("Paid tracing is not initialized. Make sure to call initializeTracing() first.");
|
|
96
103
|
}
|
|
97
|
-
|
|
104
|
+
const { externalCustomerId, externalProductId: externalAgentId, storePrompt, metadata } = options;
|
|
105
|
+
return yield tracer.startActiveSpan("parent_span", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
98
106
|
span.setAttribute("external_customer_id", externalCustomerId);
|
|
99
107
|
span.setAttribute("token", token);
|
|
100
108
|
if (externalAgentId) {
|
|
101
109
|
span.setAttribute("external_agent_id", externalAgentId);
|
|
102
110
|
}
|
|
103
111
|
try {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}));
|
|
112
|
+
const res = yield (0, tracingContext_js_1.runWithTracingContext)({
|
|
113
|
+
externalCustomerId,
|
|
114
|
+
externalProductId: externalAgentId,
|
|
115
|
+
storePrompt,
|
|
116
|
+
metadata,
|
|
117
|
+
}, () => __awaiter(this, void 0, void 0, function* () { return yield fn(...args); }));
|
|
111
118
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
112
|
-
return
|
|
119
|
+
return res;
|
|
113
120
|
}
|
|
114
121
|
catch (error) {
|
|
115
122
|
span.setStatus({
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface TracingContext {
|
|
2
|
+
externalCustomerId?: string;
|
|
3
|
+
externalProductId?: string;
|
|
4
|
+
storePrompt?: boolean;
|
|
5
|
+
metadata?: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export declare const getTracingContext: () => TracingContext;
|
|
8
|
+
export declare function runWithTracingContext<F extends (...args: any) => any>(ctx: TracingContext, fn: F): Promise<ReturnType<F>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTracingContext = void 0;
|
|
13
|
+
exports.runWithTracingContext = runWithTracingContext;
|
|
14
|
+
const async_hooks_1 = require("async_hooks");
|
|
15
|
+
const getDefaultTracingContext = () => ({
|
|
16
|
+
externalCustomerId: undefined,
|
|
17
|
+
externalProductId: undefined,
|
|
18
|
+
storePrompt: false,
|
|
19
|
+
metadata: undefined,
|
|
20
|
+
});
|
|
21
|
+
const tracingContextStorage = new async_hooks_1.AsyncLocalStorage();
|
|
22
|
+
const getTracingContext = () => tracingContextStorage.getStore() || getDefaultTracingContext();
|
|
23
|
+
exports.getTracingContext = getTracingContext;
|
|
24
|
+
function runWithTracingContext(ctx, fn) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return yield tracingContextStorage.run(ctx, fn);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -11,11 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PaidAnthropic = void 0;
|
|
13
13
|
const api_1 = require("@opentelemetry/api");
|
|
14
|
-
const tracing_js_1 = require("
|
|
14
|
+
const tracing_js_1 = require("tracing/tracing.js");
|
|
15
|
+
const tracingContext_js_1 = require("tracing/tracingContext.js");
|
|
15
16
|
class PaidAnthropic {
|
|
16
17
|
constructor(anthropicClient) {
|
|
17
18
|
this.anthropic = anthropicClient;
|
|
18
|
-
|
|
19
|
+
const tracer = (0, tracing_js_1.getPaidTracer)();
|
|
20
|
+
if (!tracer) {
|
|
21
|
+
throw new Error("Paid tracer is not initialized, Make sure to call 'initializeTracing()' first");
|
|
22
|
+
}
|
|
23
|
+
this.tracer = tracer;
|
|
19
24
|
}
|
|
20
25
|
get messages() {
|
|
21
26
|
return new MessagesWrapper(this.anthropic, this.tracer);
|
|
@@ -29,9 +34,8 @@ class MessagesWrapper {
|
|
|
29
34
|
}
|
|
30
35
|
create(params) {
|
|
31
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const token = (0, tracing_js_1.getTokenStorage)();
|
|
37
|
+
const token = (0, tracing_js_1.getToken)();
|
|
38
|
+
const { externalProductId, externalCustomerId } = (0, tracingContext_js_1.getTracingContext)();
|
|
35
39
|
if (!token || !externalCustomerId) {
|
|
36
40
|
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
37
41
|
}
|
|
@@ -42,8 +46,8 @@ class MessagesWrapper {
|
|
|
42
46
|
external_customer_id: externalCustomerId,
|
|
43
47
|
token: token,
|
|
44
48
|
};
|
|
45
|
-
if (
|
|
46
|
-
attributes["external_agent_id"] =
|
|
49
|
+
if (externalProductId) {
|
|
50
|
+
attributes["external_agent_id"] = externalProductId;
|
|
47
51
|
}
|
|
48
52
|
// Set request model from params
|
|
49
53
|
if (params.model) {
|
|
@@ -12,13 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.PaidLangChainCallback = void 0;
|
|
13
13
|
const base_1 = require("@langchain/core/callbacks/base");
|
|
14
14
|
const api_1 = require("@opentelemetry/api");
|
|
15
|
-
const tracing_js_1 = require("
|
|
15
|
+
const tracing_js_1 = require("tracing/tracing.js");
|
|
16
|
+
const tracingContext_js_1 = require("tracing/tracingContext.js");
|
|
16
17
|
class PaidLangChainCallback extends base_1.BaseCallbackHandler {
|
|
17
18
|
constructor() {
|
|
18
19
|
super();
|
|
19
20
|
this.name = "PaidLangChainCallback";
|
|
20
21
|
this.spans = new Map();
|
|
21
|
-
|
|
22
|
+
const tracer = (0, tracing_js_1.getPaidTracer)();
|
|
23
|
+
if (!tracer) {
|
|
24
|
+
throw new Error("Paid tracer is not initialized, Make sure to call 'initializeTracing()' first");
|
|
25
|
+
}
|
|
26
|
+
this.tracer = tracer;
|
|
22
27
|
}
|
|
23
28
|
extractProvider(serialized) {
|
|
24
29
|
if (!(serialized === null || serialized === void 0 ? void 0 : serialized.id))
|
|
@@ -40,9 +45,8 @@ class PaidLangChainCallback extends base_1.BaseCallbackHandler {
|
|
|
40
45
|
}
|
|
41
46
|
handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata) {
|
|
42
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const externalCustomerId = (0,
|
|
44
|
-
const
|
|
45
|
-
const token = (0, tracing_js_1.getTokenStorage)();
|
|
48
|
+
const { externalProductId, externalCustomerId } = (0, tracingContext_js_1.getTracingContext)();
|
|
49
|
+
const token = (0, tracing_js_1.getToken)();
|
|
46
50
|
if (!token || !externalCustomerId) {
|
|
47
51
|
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
48
52
|
}
|
|
@@ -57,8 +61,8 @@ class PaidLangChainCallback extends base_1.BaseCallbackHandler {
|
|
|
57
61
|
external_customer_id: externalCustomerId,
|
|
58
62
|
token: token,
|
|
59
63
|
};
|
|
60
|
-
if (
|
|
61
|
-
attributes["external_agent_id"] =
|
|
64
|
+
if (externalProductId) {
|
|
65
|
+
attributes["external_agent_id"] = externalProductId;
|
|
62
66
|
}
|
|
63
67
|
span.setAttributes(attributes);
|
|
64
68
|
this.spans.set(runId, span);
|
|
@@ -11,11 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PaidMistral = void 0;
|
|
13
13
|
const api_1 = require("@opentelemetry/api");
|
|
14
|
-
const tracing_js_1 = require("
|
|
14
|
+
const tracing_js_1 = require("tracing/tracing.js");
|
|
15
|
+
const tracingContext_js_1 = require("tracing/tracingContext.js");
|
|
15
16
|
class PaidMistral {
|
|
16
17
|
constructor(mistralClient) {
|
|
17
18
|
this.mistral = mistralClient;
|
|
18
|
-
|
|
19
|
+
const tracer = (0, tracing_js_1.getPaidTracer)();
|
|
20
|
+
if (!tracer) {
|
|
21
|
+
throw new Error("Paid tracer is not initialized, Make sure to call 'initializeTracing()' first");
|
|
22
|
+
}
|
|
23
|
+
this.tracer = tracer;
|
|
19
24
|
}
|
|
20
25
|
get ocr() {
|
|
21
26
|
return new OCRWrapper(this.mistral, this.tracer);
|
|
@@ -29,9 +34,8 @@ class OCRWrapper {
|
|
|
29
34
|
}
|
|
30
35
|
process(request, options) {
|
|
31
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const token = (0, tracing_js_1.getTokenStorage)();
|
|
37
|
+
const token = (0, tracing_js_1.getToken)();
|
|
38
|
+
const { externalProductId, externalCustomerId } = (0, tracingContext_js_1.getTracingContext)();
|
|
35
39
|
if (!token || !externalCustomerId) {
|
|
36
40
|
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
37
41
|
}
|
|
@@ -43,8 +47,8 @@ class OCRWrapper {
|
|
|
43
47
|
external_customer_id: externalCustomerId,
|
|
44
48
|
token: token,
|
|
45
49
|
};
|
|
46
|
-
if (
|
|
47
|
-
attributes["external_agent_id"] =
|
|
50
|
+
if (externalProductId) {
|
|
51
|
+
attributes["external_agent_id"] = externalProductId;
|
|
48
52
|
}
|
|
49
53
|
// Check if annotations are requested
|
|
50
54
|
if (request.bboxAnnotationFormat || request.documentAnnotationFormat) {
|