@arizeai/openinference-instrumentation-openai 3.2.0 → 3.2.2
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 +38 -1
- package/dist/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +61 -3
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esnext/instrumentation.d.ts.map +1 -1
- package/dist/esnext/instrumentation.js +62 -4
- package/dist/esnext/instrumentation.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.js +62 -4
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/instrumentation.ts +67 -3
- package/src/version.ts +1 -1
package/src/instrumentation.ts
CHANGED
|
@@ -94,6 +94,69 @@ function getExecContext(span: Span) {
|
|
|
94
94
|
}
|
|
95
95
|
return execContext;
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Gets the appropriate LLM provider based on the OpenAI client instance
|
|
100
|
+
* Follows the same logic as the Python implementation by checking the baseURL host
|
|
101
|
+
* @param clientInstance The OpenAI client instance
|
|
102
|
+
* @returns LLMProvider.AZURE for Azure OpenAI, LLMProvider.OPENAI for regular OpenAI
|
|
103
|
+
*/
|
|
104
|
+
function getLLMProvider(clientInstance: unknown): LLMProvider {
|
|
105
|
+
try {
|
|
106
|
+
// The clientInstance might be a sub-object (like Completions) that has a _client property
|
|
107
|
+
// pointing to the actual OpenAI/AzureOpenAI client
|
|
108
|
+
const instance = clientInstance as {
|
|
109
|
+
baseURL?: string | { host?: string };
|
|
110
|
+
_client?: {
|
|
111
|
+
baseURL?: string | { host?: string };
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
let host: string | undefined;
|
|
116
|
+
let baseURL: string | { host?: string } | undefined;
|
|
117
|
+
|
|
118
|
+
// First try to get baseURL from the instance itself
|
|
119
|
+
if (instance.baseURL) {
|
|
120
|
+
baseURL = instance.baseURL;
|
|
121
|
+
}
|
|
122
|
+
// If not found, try the _client property (this is where Azure OpenAI stores it)
|
|
123
|
+
else if (instance._client?.baseURL) {
|
|
124
|
+
baseURL = instance._client.baseURL;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (typeof baseURL === "string") {
|
|
128
|
+
// Extract host from URL string
|
|
129
|
+
try {
|
|
130
|
+
const url = new URL(baseURL);
|
|
131
|
+
host = url.hostname;
|
|
132
|
+
} catch {
|
|
133
|
+
// If URL parsing fails, fallback to string matching
|
|
134
|
+
host = baseURL;
|
|
135
|
+
}
|
|
136
|
+
} else if (baseURL && typeof baseURL === "object" && "host" in baseURL) {
|
|
137
|
+
// Direct host property
|
|
138
|
+
host = baseURL.host;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (host && typeof host === "string") {
|
|
142
|
+
// Follow the same pattern as Python implementation
|
|
143
|
+
if (host.includes("api.openai.com")) {
|
|
144
|
+
return LLMProvider.OPENAI;
|
|
145
|
+
} else if (host.includes("openai.azure.com")) {
|
|
146
|
+
return LLMProvider.AZURE;
|
|
147
|
+
} else if (host.includes("api.microsoft.com")) {
|
|
148
|
+
// Additional Azure endpoint pattern
|
|
149
|
+
return LLMProvider.AZURE;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
// If we can't determine, default to regular OpenAI
|
|
154
|
+
diag.debug("Failed to determine LLM provider from instance", error);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Default to OpenAI if we can't determine
|
|
158
|
+
return LLMProvider.OPENAI;
|
|
159
|
+
}
|
|
97
160
|
/**
|
|
98
161
|
* An auto instrumentation class for OpenAI that creates {@link https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md|OpenInference} Compliant spans for the OpenAI API
|
|
99
162
|
* @param instrumentationConfig The config for the instrumentation @see {@link InstrumentationConfig}
|
|
@@ -221,7 +284,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
221
284
|
[SemanticConventions.LLM_INVOCATION_PARAMETERS]:
|
|
222
285
|
JSON.stringify(invocationParameters),
|
|
223
286
|
[SemanticConventions.LLM_SYSTEM]: LLMSystem.OPENAI,
|
|
224
|
-
[SemanticConventions.LLM_PROVIDER]:
|
|
287
|
+
[SemanticConventions.LLM_PROVIDER]: getLLMProvider(this),
|
|
225
288
|
...getLLMInputMessagesAttributes(body),
|
|
226
289
|
...getLLMToolsJSONSchema(body),
|
|
227
290
|
},
|
|
@@ -310,7 +373,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
310
373
|
[SemanticConventions.LLM_INVOCATION_PARAMETERS]:
|
|
311
374
|
JSON.stringify(invocationParameters),
|
|
312
375
|
[SemanticConventions.LLM_SYSTEM]: LLMSystem.OPENAI,
|
|
313
|
-
[SemanticConventions.LLM_PROVIDER]:
|
|
376
|
+
[SemanticConventions.LLM_PROVIDER]: getLLMProvider(this),
|
|
314
377
|
...getCompletionInputValueAndMimeType(body),
|
|
315
378
|
},
|
|
316
379
|
},
|
|
@@ -389,6 +452,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
389
452
|
[SemanticConventions.INPUT_MIME_TYPE]: isStringInput
|
|
390
453
|
? MimeType.TEXT
|
|
391
454
|
: MimeType.JSON,
|
|
455
|
+
[SemanticConventions.LLM_PROVIDER]: getLLMProvider(this),
|
|
392
456
|
...getEmbeddingTextAttributes(body),
|
|
393
457
|
},
|
|
394
458
|
});
|
|
@@ -461,7 +525,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
461
525
|
[SemanticConventions.LLM_INVOCATION_PARAMETERS]:
|
|
462
526
|
JSON.stringify(invocationParameters),
|
|
463
527
|
[SemanticConventions.LLM_SYSTEM]: LLMSystem.OPENAI,
|
|
464
|
-
[SemanticConventions.LLM_PROVIDER]:
|
|
528
|
+
[SemanticConventions.LLM_PROVIDER]: getLLMProvider(this),
|
|
465
529
|
...getResponsesInputMessagesAttributes(body),
|
|
466
530
|
...getLLMToolsJSONSchema(body),
|
|
467
531
|
},
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// this is an auto-generated file. see js/scripts/version-update.js
|
|
2
|
-
export const VERSION = "3.2.
|
|
2
|
+
export const VERSION = "3.2.2";
|