@sweetoburrito/backstage-plugin-ai-assistant-backend-module-callback-provider-langfuse 0.0.0-snapshot-20251113134620

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 ADDED
@@ -0,0 +1,113 @@
1
+ # @sweetoburrito/backstage-plugin-ai-assistant-backend-module-callback-provider-langfuse
2
+
3
+ A callback provider module that integrates Langfuse observability into the Backstage AI Assistant backend, enabling tracing, monitoring, and analytics of LLM interactions.
4
+
5
+ This README explains how the provider works, when to use it, configuration options, and how to wire it into your Backstage backend.
6
+
7
+ ## Features
8
+
9
+ - Automatically trace all LLM calls, agent executions, and tool invocations through Langfuse.
10
+ - Track token usage, costs, and performance metrics for each conversation.
11
+ - Debug AI interactions with detailed execution traces in the Langfuse dashboard.
12
+ - Monitor user behavior and conversation patterns across your organization.
13
+ - Integrates with both Langfuse Cloud and self-hosted Langfuse instances.
14
+ - Uses OpenTelemetry for comprehensive tracing alongside LangChain callbacks.
15
+
16
+ ## When to use
17
+
18
+ Use this module if you want to:
19
+
20
+ - Monitor and debug your AI Assistant interactions in production
21
+ - Track LLM costs and token usage across models and users
22
+ - Analyze conversation patterns and user behavior
23
+ - Maintain audit logs of AI interactions for compliance
24
+ - Optimize prompts and model performance based on real usage data
25
+ - Get visibility into agent decision-making and tool usage
26
+
27
+ ## Configuration
28
+
29
+ Add the provider configuration to your Backstage `app-config.yaml` or `app-config.local.yaml` under `aiAssistant.callbacks.langfuse`.
30
+
31
+ Minimum configuration keys (example):
32
+
33
+ ```yaml
34
+ aiAssistant:
35
+ callbacks:
36
+ langfuse:
37
+ secretKey: ${LANGFUSE_SECRET_KEY}
38
+ publicKey: ${LANGFUSE_PUBLIC_KEY}
39
+ baseUrl: https://cloud.langfuse.com
40
+ ```
41
+
42
+ ### Field descriptions
43
+
44
+ - `secretKey` - Your Langfuse secret API key (starts with `sk-lf-`). Marked as secret in configuration.
45
+ - `publicKey` - Your Langfuse public API key (starts with `pk-lf-`). Marked as secret in configuration.
46
+ - `baseUrl` - The Langfuse instance URL (e.g., `https://cloud.langfuse.com`, `https://us.cloud.langfuse.com`, or your self-hosted URL)
47
+
48
+ The exact keys required depend on your Langfuse configuration. Check the provider's `config.d.ts` in the package for the canonical types used by the module.
49
+
50
+ ## Install
51
+
52
+ Install the module into your Backstage backend workspace:
53
+
54
+ ```sh
55
+ yarn workspace backend add @sweetoburrito/backstage-plugin-ai-assistant-backend-module-callback-provider-langfuse
56
+ ```
57
+
58
+ ## Wire the provider into your backend
59
+
60
+ Add the provider module import to your backend entrypoint (usually `packages/backend/src/index.ts`):
61
+
62
+ ```diff
63
+ // packages/backend/src/index.ts
64
+
65
+ // other backend modules...
66
+ backend.add(import('@sweetoburrito/backstage-plugin-ai-assistant-backend'));
67
+
68
+ // Add the Langfuse callback provider
69
+ ++backend.add(
70
+ ++ import(
71
+ ++ '@sweetoburrito/backstage-plugin-ai-assistant-backend-module-callback-provider-langfuse'
72
+ ++ ),
73
+ ++);
74
+ ```
75
+
76
+ Restart your backend after adding the provider so it registers with the AI Assistant plugin.
77
+
78
+ ## What gets tracked
79
+
80
+ The Langfuse callback provider automatically captures:
81
+
82
+ - **Conversations**: Full conversation history with user and assistant messages
83
+ - **Model calls**: All LLM invocations including prompts, completions, and parameters
84
+ - **Tool usage**: When agents use tools like search, catalog lookups, or custom tools
85
+ - **Token metrics**: Input/output tokens for cost and usage tracking
86
+ - **Performance**: Latency and execution time for each operation
87
+ - **Errors**: Failed requests with error messages and stack traces
88
+ - **Metadata**: User entity references, model IDs, session IDs, and custom tags
89
+
90
+ ## Verification
91
+
92
+ Once configured and running:
93
+
94
+ 1. Use the AI Assistant in Backstage to ask a question
95
+ 2. Log in to your Langfuse dashboard
96
+ 3. Navigate to the **Traces** section
97
+ 4. You should see traces appearing with tags like `backstage-ai-assistant` and `chat`
98
+
99
+ Each trace includes:
100
+
101
+ - User queries and AI responses
102
+ - Model calls with prompts and completions
103
+ - Token usage and costs
104
+ - Tool invocations
105
+ - Performance metrics
106
+ - User and session information
107
+
108
+ ## Additional Resources
109
+
110
+ - [Langfuse Documentation](https://langfuse.com/docs)
111
+ - [Langfuse Setup Guide for AI Assistant](https://github.com/SweetOBurritO/backstage-plugin-ai-assistant/blob/main/docs/langfuse.md)
112
+ - [Creating Custom Callback Providers](https://github.com/SweetOBurritO/backstage-plugin-ai-assistant/blob/main/docs/callbacks/creating-callback-provider.md)
113
+ - [Callback Providers Overview](https://github.com/SweetOBurritO/backstage-plugin-ai-assistant/blob/main/docs/callbacks/index.md)
package/config.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ export interface Config {
2
+ aiAssistant: {
3
+ callbacks: {
4
+ langfuse: {
5
+ baseUrl: string;
6
+
7
+ /**
8
+ * @visibility secret
9
+ */
10
+ publicKey: string;
11
+
12
+ /**
13
+ * @visibility secret
14
+ */
15
+ secretKey: string;
16
+ };
17
+ };
18
+ };
19
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var module$1 = require('./module.cjs.js');
6
+
7
+
8
+
9
+ exports.default = module$1.aiAssistantModuleCallbackProviderLangfuse;
10
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,5 @@
1
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+
3
+ declare const aiAssistantModuleCallbackProviderLangfuse: _backstage_backend_plugin_api.BackendFeature;
4
+
5
+ export { aiAssistantModuleCallbackProviderLangfuse as default };
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var otel = require('@langfuse/otel');
5
+ var sdkNode = require('@opentelemetry/sdk-node');
6
+ var langchain = require('@langfuse/langchain');
7
+ var backstagePluginAiAssistantNode = require('@sweetoburrito/backstage-plugin-ai-assistant-node');
8
+
9
+ const aiAssistantModuleCallbackProviderLangfuse = backendPluginApi.createBackendModule({
10
+ pluginId: "ai-assistant",
11
+ moduleId: "callback-provider-langfuse",
12
+ register(reg) {
13
+ reg.registerInit({
14
+ deps: {
15
+ config: backendPluginApi.coreServices.rootConfig,
16
+ callbackProvider: backstagePluginAiAssistantNode.callbackFactoryExtensionPoint
17
+ },
18
+ async init({ config, callbackProvider }) {
19
+ const secretKey = config.getString(
20
+ "aiAssistant.callbacks.langfuse.secretKey"
21
+ );
22
+ const publicKey = config.getString(
23
+ "aiAssistant.callbacks.langfuse.publicKey"
24
+ );
25
+ const baseUrl = config.getString(
26
+ "aiAssistant.callbacks.langfuse.baseUrl"
27
+ );
28
+ const langfuseSpanProcessor = new otel.LangfuseSpanProcessor({
29
+ secretKey,
30
+ publicKey,
31
+ baseUrl
32
+ });
33
+ const sdk = new sdkNode.NodeSDK({
34
+ spanProcessors: [langfuseSpanProcessor]
35
+ });
36
+ sdk.start();
37
+ callbackProvider.register(async (options) => {
38
+ const { conversationId, userId, modelId } = options;
39
+ const callback = new langchain.CallbackHandler({
40
+ sessionId: conversationId,
41
+ userId,
42
+ tags: ["backstage-ai-assistant", "chat", modelId]
43
+ });
44
+ const metadata = {
45
+ langfuseUserId: userId,
46
+ langfuseSessionId: conversationId,
47
+ langfuseTags: ["ai-assistant", "chat", modelId]
48
+ };
49
+ return {
50
+ callback,
51
+ metadata
52
+ };
53
+ });
54
+ }
55
+ });
56
+ }
57
+ });
58
+
59
+ exports.aiAssistantModuleCallbackProviderLangfuse = aiAssistantModuleCallbackProviderLangfuse;
60
+ //# sourceMappingURL=module.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["import {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { LangfuseSpanProcessor } from '@langfuse/otel';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { CallbackHandler } from '@langfuse/langchain';\nimport { callbackFactoryExtensionPoint } from '@sweetoburrito/backstage-plugin-ai-assistant-node';\n\nexport const aiAssistantModuleCallbackProviderLangfuse = createBackendModule({\n pluginId: 'ai-assistant',\n moduleId: 'callback-provider-langfuse',\n register(reg) {\n reg.registerInit({\n deps: {\n config: coreServices.rootConfig,\n callbackProvider: callbackFactoryExtensionPoint,\n },\n async init({ config, callbackProvider }) {\n const secretKey = config.getString(\n 'aiAssistant.callbacks.langfuse.secretKey',\n );\n const publicKey = config.getString(\n 'aiAssistant.callbacks.langfuse.publicKey',\n );\n const baseUrl = config.getString(\n 'aiAssistant.callbacks.langfuse.baseUrl',\n );\n\n const langfuseSpanProcessor = new LangfuseSpanProcessor({\n secretKey,\n publicKey,\n baseUrl,\n });\n\n const sdk = new NodeSDK({\n spanProcessors: [langfuseSpanProcessor],\n });\n\n sdk.start();\n\n callbackProvider.register(async options => {\n const { conversationId, userId, modelId } = options;\n const callback = new CallbackHandler({\n sessionId: conversationId,\n userId,\n tags: ['backstage-ai-assistant', 'chat', modelId],\n });\n\n const metadata = {\n langfuseUserId: userId,\n langfuseSessionId: conversationId,\n langfuseTags: ['ai-assistant', 'chat', modelId],\n };\n\n return {\n callback,\n metadata,\n };\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","coreServices","callbackFactoryExtensionPoint","LangfuseSpanProcessor","NodeSDK","CallbackHandler"],"mappings":";;;;;;;;AASO,MAAM,4CAA4CA,oCAAA,CAAoB;AAAA,EAC3E,QAAA,EAAU,cAAA;AAAA,EACV,QAAA,EAAU,4BAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,QAAQC,6BAAA,CAAa,UAAA;AAAA,QACrB,gBAAA,EAAkBC;AAAA,OACpB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,kBAAiB,EAAG;AACvC,QAAA,MAAM,YAAY,MAAA,CAAO,SAAA;AAAA,UACvB;AAAA,SACF;AACA,QAAA,MAAM,YAAY,MAAA,CAAO,SAAA;AAAA,UACvB;AAAA,SACF;AACA,QAAA,MAAM,UAAU,MAAA,CAAO,SAAA;AAAA,UACrB;AAAA,SACF;AAEA,QAAA,MAAM,qBAAA,GAAwB,IAAIC,0BAAA,CAAsB;AAAA,UACtD,SAAA;AAAA,UACA,SAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,MAAM,GAAA,GAAM,IAAIC,eAAA,CAAQ;AAAA,UACtB,cAAA,EAAgB,CAAC,qBAAqB;AAAA,SACvC,CAAA;AAED,QAAA,GAAA,CAAI,KAAA,EAAM;AAEV,QAAA,gBAAA,CAAiB,QAAA,CAAS,OAAM,OAAA,KAAW;AACzC,UAAA,MAAM,EAAE,cAAA,EAAgB,MAAA,EAAQ,OAAA,EAAQ,GAAI,OAAA;AAC5C,UAAA,MAAM,QAAA,GAAW,IAAIC,yBAAA,CAAgB;AAAA,YACnC,SAAA,EAAW,cAAA;AAAA,YACX,MAAA;AAAA,YACA,IAAA,EAAM,CAAC,wBAAA,EAA0B,MAAA,EAAQ,OAAO;AAAA,WACjD,CAAA;AAED,UAAA,MAAM,QAAA,GAAW;AAAA,YACf,cAAA,EAAgB,MAAA;AAAA,YAChB,iBAAA,EAAmB,cAAA;AAAA,YACnB,YAAA,EAAc,CAAC,cAAA,EAAgB,MAAA,EAAQ,OAAO;AAAA,WAChD;AAEA,UAAA,OAAO;AAAA,YACL,QAAA;AAAA,YACA;AAAA,WACF;AAAA,QACF,CAAC,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@sweetoburrito/backstage-plugin-ai-assistant-backend-module-callback-provider-langfuse",
3
+ "version": "0.0.0-snapshot-20251113134620",
4
+ "license": "Apache-2.0",
5
+ "description": "The callback-provider-langfuse backend module for the ai-assistant plugin.",
6
+ "main": "dist/index.cjs.js",
7
+ "types": "dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "main": "dist/index.cjs.js",
11
+ "types": "dist/index.d.ts"
12
+ },
13
+ "backstage": {
14
+ "role": "backend-plugin-module",
15
+ "pluginId": "ai-assistant",
16
+ "pluginPackage": "@sweetoburrito/backstage-plugin-ai-assistant-backend",
17
+ "features": {
18
+ ".": "@backstage/BackendFeature"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "start": "backstage-cli package start",
23
+ "build": "backstage-cli package build",
24
+ "lint": "backstage-cli package lint",
25
+ "test": "backstage-cli package test",
26
+ "clean": "backstage-cli package clean",
27
+ "prepack": "backstage-cli package prepack",
28
+ "postpack": "backstage-cli package postpack"
29
+ },
30
+ "dependencies": {
31
+ "@backstage/backend-plugin-api": "backstage:^",
32
+ "@langfuse/langchain": "^4.4.2",
33
+ "@langfuse/otel": "^4.4.2",
34
+ "@opentelemetry/sdk-node": "^0.208.0",
35
+ "@sweetoburrito/backstage-plugin-ai-assistant-node": "workspace:^"
36
+ },
37
+ "devDependencies": {
38
+ "@backstage/backend-test-utils": "backstage:^",
39
+ "@backstage/cli": "backstage:^"
40
+ },
41
+ "configSchema": "config.d.ts",
42
+ "files": [
43
+ "dist",
44
+ "config.d.ts"
45
+ ],
46
+ "typesVersions": {
47
+ "*": {
48
+ "package.json": [
49
+ "package.json"
50
+ ]
51
+ }
52
+ }
53
+ }