-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffold otel + arize phoenix integration
- Loading branch information
1 parent
eaa70f0
commit 555f42d
Showing
19 changed files
with
1,942 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ConsoleSpanExporter, WebTracerProvider, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-web" | ||
import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions"; | ||
import { Resource } from "@opentelemetry/resources" | ||
import * as lcCallbackManager from "@langchain/core/callbacks/manager"; | ||
import { LangChainInstrumentation } from "web-instrumentation-langchain"; | ||
|
||
import { TracingConfig } from "src/run" | ||
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"; | ||
|
||
const instrumentPhoenixLangchain = () => { | ||
const lcInstrumentation = new LangChainInstrumentation(); | ||
lcInstrumentation.manuallyInstrument(lcCallbackManager); | ||
|
||
console.log("🔎 Phoenix Langchain instrumentation enabled 🔎") | ||
} | ||
|
||
export const createPhoenixWebTracerProvider = ({ tracingConfig }: { tracingConfig: TracingConfig }) => { | ||
if (!tracingConfig.phoenix?.enabled) { | ||
return | ||
} | ||
|
||
try { | ||
|
||
const provider = new WebTracerProvider({ | ||
resource: new Resource({ | ||
[SEMRESATTRS_PROJECT_NAME]: tracingConfig.phoenix.projectName, | ||
|
||
}), | ||
}) | ||
|
||
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())) | ||
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter({ | ||
url: tracingConfig.phoenix.baseUrl, | ||
headers: { | ||
// allow cross-origin requests | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", | ||
"Access-Control-Allow-Headers": "Content-Type, Authorization, Content-Length, X-Requested-With, Accept, Origin", | ||
"Access-Control-Allow-Credentials": "true", | ||
} | ||
}))) | ||
|
||
provider.register() | ||
|
||
console.log("🔎 Phoenix tracing enabled 🔎") | ||
|
||
instrumentPhoenixLangchain() | ||
|
||
return provider | ||
} catch (error) { | ||
console.error("Error enabling Phoenix tracing", error) | ||
} | ||
} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/cannoli-plugin/src/settings/sections/tracingSettings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Setting } from "obsidian"; | ||
import Cannoli from "src/main"; | ||
import { TracingConfig } from "@deablabs/cannoli-core"; | ||
import { DEFAULT_SETTINGS } from "src/settings/settings"; | ||
|
||
const defaultPhoenixTracingConfig: NonNullable<TracingConfig["phoenix"]> = DEFAULT_SETTINGS.tracingConfig.phoenix! | ||
|
||
export function createTracingSettings(containerEl: HTMLElement, plugin: Cannoli, display: () => void): void { | ||
// heading | ||
containerEl.createEl("h1", { text: "Tracing" }); | ||
|
||
new Setting(containerEl) | ||
.setName("Phoenix Tracing") | ||
.setDesc("Enable Phoenix tracing for your Cannoli runs. Phoenix is a data tracing system that allows you to observe the history of your runs, and optimize your prompts over time.") | ||
.addToggle((toggle) => { | ||
toggle.setValue(plugin.settings.tracingConfig.phoenix?.enabled ?? false); | ||
toggle.onChange(async (value) => { | ||
if (plugin.settings.tracingConfig.phoenix) { | ||
plugin.settings.tracingConfig.phoenix.enabled = value; | ||
} else { | ||
plugin.settings.tracingConfig.phoenix = { | ||
...defaultPhoenixTracingConfig, | ||
enabled: value, | ||
} | ||
} | ||
await plugin.saveSettings(); | ||
display(); | ||
}); | ||
}); | ||
|
||
new Setting(containerEl) | ||
.setName("Phoenix Project Name") | ||
.setDesc("The name of the project to use for your Phoenix tracing. This is used to identify the project in the Phoenix console.") | ||
.addText((text) => { | ||
text.setValue(plugin.settings.tracingConfig.phoenix?.projectName ?? defaultPhoenixTracingConfig.projectName); | ||
text.onChange(async (value) => { | ||
if (plugin.settings.tracingConfig.phoenix) { | ||
plugin.settings.tracingConfig.phoenix.projectName = value; | ||
} else { | ||
plugin.settings.tracingConfig.phoenix = { | ||
...defaultPhoenixTracingConfig, | ||
projectName: value, | ||
} | ||
} | ||
await plugin.saveSettings(); | ||
}); | ||
}); | ||
|
||
new Setting(containerEl) | ||
.setName("Phoenix Base URL") | ||
.setDesc("The base URL for your Phoenix tracing. This is used to send your tracing data to the Phoenix server.") | ||
.addText((text) => { | ||
text.setValue(plugin.settings.tracingConfig.phoenix?.baseUrl ?? defaultPhoenixTracingConfig.baseUrl); | ||
text.onChange(async (value) => { | ||
if (plugin.settings.tracingConfig.phoenix) { | ||
plugin.settings.tracingConfig.phoenix.baseUrl = value; | ||
} else { | ||
plugin.settings.tracingConfig.phoenix = { | ||
...defaultPhoenixTracingConfig, | ||
baseUrl: value, | ||
} | ||
} | ||
await plugin.saveSettings(); | ||
}); | ||
}); | ||
|
||
new Setting(containerEl) | ||
.setName("Phoenix API Key") | ||
.setDesc("The API key to use for your Phoenix tracing. This is used to authenticate your tracing data to the Phoenix server.") | ||
.addText((text) => { | ||
text.setValue(plugin.settings.tracingConfig.phoenix?.apiKey ?? defaultPhoenixTracingConfig.apiKey ?? ""); | ||
text.onChange(async (value) => { | ||
if (plugin.settings.tracingConfig.phoenix) { | ||
plugin.settings.tracingConfig.phoenix.apiKey = value; | ||
} else { | ||
plugin.settings.tracingConfig.phoenix = { | ||
...defaultPhoenixTracingConfig, | ||
apiKey: value, | ||
} | ||
} | ||
await plugin.saveSettings(); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.