Add domain to openai compatible telemetry (#7170)

* OpenAI compatible domain telemetry

* Updated tests for openAiCompatibleDomain inclusion in telemtry
This commit is contained in:
canvrno authored and GitHub committed 2025-10-29 15:51:50 -07:00
1 parent b877abc708
commit 19f74cac01
5 files changed
+40 -7

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Telemtry change: collect domain of openai compatible endpoints when telemetry is enabled
+10 -3
View File
@@ -94,7 +94,7 @@ import { FocusChainManager } from "./focus-chain"
import { MessageStateHandler } from "./message-state"
import { TaskState } from "./TaskState"
import { ToolExecutor } from "./ToolExecutor"
import { detectAvailableCliTools, updateApiReqMsg } from "./utils"
import { detectAvailableCliTools, extractProviderDomainFromUrl, updateApiReqMsg } from "./utils"
export type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
type UserContent = Array<Anthropic.ContentBlockParam>
@@ -452,12 +452,19 @@ export class Task {
}
// initialize telemetry
// Extract domain of the provider endpoint if using OpenAI Compatible provider
let openAiCompatibleDomain: string | undefined
if (currentProvider === "openai" && apiConfiguration.openAiBaseUrl) {
openAiCompatibleDomain = extractProviderDomainFromUrl(apiConfiguration.openAiBaseUrl)
}
if (historyItem) {
// Open task from history
telemetryService.captureTaskRestarted(this.ulid, currentProvider)
telemetryService.captureTaskRestarted(this.ulid, currentProvider, openAiCompatibleDomain)
} else {
// New task started
telemetryService.captureTaskCreated(this.ulid, currentProvider)
telemetryService.captureTaskCreated(this.ulid, currentProvider, openAiCompatibleDomain)
}
this.toolExecutor = new ToolExecutor(
+17
View File
@@ -132,3 +132,20 @@ export async function detectAvailableCliTools(): Promise<string[]> {
return availableCommands
}
/**
* Extracts the domain from a provider URL string
* @param url The URL to extract domain from
* @returns The domain/hostname or undefined if invalid
*/
export function extractProviderDomainFromUrl(url: string | undefined): string | undefined {
if (!url) {
return undefined
}
try {
const urlObj = new URL(url)
return urlObj.hostname
} catch {
return undefined
}
}
@@ -66,6 +66,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
{
ulid: "task-456",
apiProvider: "openai",
openAiCompatibleDomain: undefined,
...MOCK_METADATA,
},
"Task created event should include only the expected metadata properties",
@@ -125,6 +126,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
const expectedProperties = {
ulid: "multi-task-123",
apiProvider: "anthropic",
openAiCompatibleDomain: undefined,
...MOCK_METADATA,
}
assert.deepStrictEqual(properties1, expectedProperties, "First provider should receive correct properties")
+6 -4
View File
@@ -533,11 +533,12 @@ export class TelemetryService {
* Records when a new task/conversation is started
* @param ulid Unique identifier for the new task
* @param apiProvider Optional API provider
* @param openAiCompatibleDomain Optional domain for OpenAI Compatible providers (e.g., "api.example.com")
*/
public captureTaskCreated(ulid: string, apiProvider?: string) {
public captureTaskCreated(ulid: string, apiProvider?: string, openAiCompatibleDomain?: string) {
this.capture({
event: TelemetryService.EVENTS.TASK.CREATED,
properties: { ulid, apiProvider },
properties: { ulid, apiProvider, openAiCompatibleDomain },
})
}
@@ -545,11 +546,12 @@ export class TelemetryService {
* Records when a task/conversation is restarted
* @param ulid Unique identifier for the new task
* @param apiProvider Optional API provider
* @param openAiCompatibleDomain Optional domain for OpenAI Compatible providers (e.g., "api.example.com")
*/
public captureTaskRestarted(ulid: string, apiProvider?: string) {
public captureTaskRestarted(ulid: string, apiProvider?: string, openAiCompatibleDomain?: string) {
this.capture({
event: TelemetryService.EVENTS.TASK.RESTARTED,
properties: { ulid, apiProvider },
properties: { ulid, apiProvider, openAiCompatibleDomain },
})
}