@struct-ai/sdk 0.4.2 → 0.4.4
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 +22 -0
- package/dist/commonjs/integrations/openai.js +18 -0
- package/dist/commonjs/version.d.ts +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/integrations/openai.js +18 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -293,6 +293,28 @@ Emits attributes per the OTel GenAI semantic conventions:
|
|
|
293
293
|
- `gen_ai.tool.{name, call.id, call.arguments, call.result}`
|
|
294
294
|
- `error.type` + `StatusCode.ERROR` on failures
|
|
295
295
|
|
|
296
|
+
### `error.type` values emitted
|
|
297
|
+
|
|
298
|
+
The OTel conventions ask instrumentations to document the error values they
|
|
299
|
+
report ("Instrumentations SHOULD document the list of errors they report").
|
|
300
|
+
This SDK emits exactly two kinds of value, both alongside span
|
|
301
|
+
`StatusCode.ERROR`:
|
|
302
|
+
|
|
303
|
+
| Value | When | Meaning |
|
|
304
|
+
| --- | --- | --- |
|
|
305
|
+
| exception class name (e.g. `TypeError`, `APIConnectionError`) | the instrumented call threw | We failed to execute the request. Also records an OTel exception event. |
|
|
306
|
+
| `tool_error` | an `execute_tool` span whose result signalled failure **in band** — Anthropic `tool_result` blocks with `is_error: true`, MCP `CallToolResult.isError`, or a LangChain `ToolMessage` with `status: "error"` | The tool ran and reported a failure back to the model (bad arguments, a domain "no"), so the model can self-correct. No exception object exists, so no class name is available. |
|
|
307
|
+
|
|
308
|
+
`tool_error` is a deliberate low-cardinality sentinel, which the `error.type`
|
|
309
|
+
convention explicitly permits ("another low-cardinality error identifier"; a
|
|
310
|
+
custom value MAY be used where no well-known one applies). The same split is
|
|
311
|
+
used by OpenTelemetry's MCP instrumentation in OpenLLMetry, which likewise
|
|
312
|
+
reports `error.type="tool_error"` for the `isError` path and the exception
|
|
313
|
+
class name otherwise. Matches the Python SDK.
|
|
314
|
+
|
|
315
|
+
The distinction is what lets a monitor page on genuine execution failures
|
|
316
|
+
while excluding failures the model already saw and can recover from.
|
|
317
|
+
|
|
296
318
|
Note: `gen_ai.usage.input_tokens` for Anthropic is the TRUE total — we add back
|
|
297
319
|
`cache_read_input_tokens + cache_creation_input_tokens` (which Anthropic's raw
|
|
298
320
|
response excludes). Matches the Python SDK.
|
|
@@ -107,8 +107,26 @@ function isAzureHost(host) {
|
|
|
107
107
|
host.endsWith(".services.ai.azure.us") ||
|
|
108
108
|
host.endsWith(".services.ai.azure.cn"));
|
|
109
109
|
}
|
|
110
|
+
// OpenAI-compatible vendor endpoints served through the openai client. Values
|
|
111
|
+
// are the CURRENT OTel gen_ai.provider.name well-known enum (semconv-genai
|
|
112
|
+
// registry): note "x_ai" (underscored — the deprecated gen_ai.system enum used
|
|
113
|
+
// "xai") and "mistral_ai" (not "mistral"). Fixed API hosts, so exact-match —
|
|
114
|
+
// a lookalike like "api.x.ai.evil.com" must not match.
|
|
115
|
+
// Parity: python openai.py's _OPENAI_COMPATIBLE_HOSTS.
|
|
116
|
+
const OPENAI_COMPATIBLE_HOSTS = new Map([
|
|
117
|
+
["api.x.ai", "x_ai"],
|
|
118
|
+
["api.groq.com", "groq"],
|
|
119
|
+
["api.deepseek.com", "deepseek"],
|
|
120
|
+
["api.mistral.ai", "mistral_ai"],
|
|
121
|
+
]);
|
|
110
122
|
const HOST_RULES = [
|
|
111
123
|
[isAzureHost, "azure.ai.openai"],
|
|
124
|
+
// One (predicate, provider) entry per fixed vendor host — the detector
|
|
125
|
+
// returns the first matching rule's value.
|
|
126
|
+
...[...OPENAI_COMPATIBLE_HOSTS].map(([vendorHost, provider]) => [
|
|
127
|
+
(host) => host === vendorHost,
|
|
128
|
+
provider,
|
|
129
|
+
]),
|
|
112
130
|
];
|
|
113
131
|
function detectProvider(resource) {
|
|
114
132
|
return (0, genai_content_js_1.detectProviderFromResource)(resource, CLASS_NAME_RULES, HOST_RULES, "openai");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.4.
|
|
1
|
+
export declare const SDK_VERSION = "0.4.4";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/commonjs/version.js
CHANGED
|
@@ -98,8 +98,26 @@ function isAzureHost(host) {
|
|
|
98
98
|
host.endsWith(".services.ai.azure.us") ||
|
|
99
99
|
host.endsWith(".services.ai.azure.cn"));
|
|
100
100
|
}
|
|
101
|
+
// OpenAI-compatible vendor endpoints served through the openai client. Values
|
|
102
|
+
// are the CURRENT OTel gen_ai.provider.name well-known enum (semconv-genai
|
|
103
|
+
// registry): note "x_ai" (underscored — the deprecated gen_ai.system enum used
|
|
104
|
+
// "xai") and "mistral_ai" (not "mistral"). Fixed API hosts, so exact-match —
|
|
105
|
+
// a lookalike like "api.x.ai.evil.com" must not match.
|
|
106
|
+
// Parity: python openai.py's _OPENAI_COMPATIBLE_HOSTS.
|
|
107
|
+
const OPENAI_COMPATIBLE_HOSTS = new Map([
|
|
108
|
+
["api.x.ai", "x_ai"],
|
|
109
|
+
["api.groq.com", "groq"],
|
|
110
|
+
["api.deepseek.com", "deepseek"],
|
|
111
|
+
["api.mistral.ai", "mistral_ai"],
|
|
112
|
+
]);
|
|
101
113
|
const HOST_RULES = [
|
|
102
114
|
[isAzureHost, "azure.ai.openai"],
|
|
115
|
+
// One (predicate, provider) entry per fixed vendor host — the detector
|
|
116
|
+
// returns the first matching rule's value.
|
|
117
|
+
...[...OPENAI_COMPATIBLE_HOSTS].map(([vendorHost, provider]) => [
|
|
118
|
+
(host) => host === vendorHost,
|
|
119
|
+
provider,
|
|
120
|
+
]),
|
|
103
121
|
];
|
|
104
122
|
function detectProvider(resource) {
|
|
105
123
|
return detectProviderFromResource(resource, CLASS_NAME_RULES, HOST_RULES, "openai");
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.4.
|
|
1
|
+
export declare const SDK_VERSION = "0.4.4";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/esm/version.js
CHANGED
package/package.json
CHANGED