Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community-experimental[minor]: feat: implement DatadogLLMObsTracer #5867

Merged
merged 11 commits into from
Jun 25, 2024
Merged
6 changes: 6 additions & 0 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ docs/tutorials/classification.md
docs/tutorials/classification.mdx
docs/tutorials/chatbot.md
docs/tutorials/chatbot.mdx
docs/how_to/trim_messages.md
docs/how_to/trim_messages.mdx
docs/how_to/tools_prompting.md
docs/how_to/tools_prompting.mdx
docs/how_to/tools_builtin.md
Expand Down Expand Up @@ -117,6 +119,8 @@ docs/how_to/multimodal_inputs.md
docs/how_to/multimodal_inputs.mdx
docs/how_to/migrate_agent.md
docs/how_to/migrate_agent.mdx
docs/how_to/merge_message_runs.md
docs/how_to/merge_message_runs.mdx
docs/how_to/logprobs.md
docs/how_to/logprobs.mdx
docs/how_to/lcel_cheatsheet.md
Expand All @@ -131,6 +135,8 @@ docs/how_to/graph_constructing.md
docs/how_to/graph_constructing.mdx
docs/how_to/functions.md
docs/how_to/functions.mdx
docs/how_to/filter_messages.md
docs/how_to/filter_messages.mdx
docs/how_to/few_shot_examples_chat.md
docs/how_to/few_shot_examples_chat.mdx
docs/how_to/few_shot_examples.md
Expand Down
31 changes: 31 additions & 0 deletions docs/core_docs/docs/integrations/callbacks/datadog_tracer.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
sidebar_class_name: beta
---

import CodeBlock from "@theme/CodeBlock";

# Datadog LLM Observability

:::warning
LLM Observability is in public beta, and its API is subject to change.
:::

With [Datadog LLM Observability](https://docs.datadoghq.com/llm_observability/), you can monitor, troubleshoot, and evaluate your LLM-powered applications, such as chatbots. You can investigate the root cause of issues, monitor operational performance, and evaluate the quality, privacy, and safety of your LLM applications.

This is an experimental community implementation, and it is not officially supported by Datadog. It is based on the [Datadog LLM Observability API](https://docs.datadoghq.com/llm_observability/api).

## Setup

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/community
```

## Usage

import UsageExample from "@examples/callbacks/datadog.ts";

<CodeBlock language="typescript">{UsageExample}</CodeBlock>
6 changes: 4 additions & 2 deletions docs/core_docs/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ nav, h1, h2, h3, h4 {
/* Override `beta` color */
.beta::after {
content: "Beta";
color: #58006e;
color: #fff;
background: #58006e;
border: 1px solid #58006e;
}

Expand All @@ -114,7 +115,8 @@ nav, h1, h2, h3, h4 {
/* Override `web-only` color */
.web-only::after {
content: "Web-only";
color: #0a0072;
color: #fff;
background: #0a0072;
border: 1px solid #0a0072;
}

Expand Down
30 changes: 30 additions & 0 deletions examples/src/callbacks/datadog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { OpenAI } from "@langchain/openai";
import { DatadogLLMObsTracer } from "@langchain/community/experimental/callbacks/handlers/datadog";

/**
* This example demonstrates how to use the DatadogLLMObsTracer with the OpenAI model.
* It will produce a "llm" span with the input and output of the model inside the meta field.
*
* To run this example, you need to have a valid Datadog API key and OpenAI API key.
*/
export const run = async () => {
const model = new OpenAI({
model: "gpt-4",
temperature: 0.7,
maxTokens: 1000,
maxRetries: 5,
});

const res = await model.invoke(
"Question: What would be a good company name a company that makes colorful socks?\nAnswer:",
{
callbacks: [
new DatadogLLMObsTracer({
mlApp: "my-ml-app",
}),
],
}
);

console.log({ res });
};
4 changes: 4 additions & 0 deletions libs/langchain-community/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ utils/cassandra.cjs
utils/cassandra.js
utils/cassandra.d.ts
utils/cassandra.d.cts
experimental/callbacks/handlers/datadog.cjs
experimental/callbacks/handlers/datadog.js
experimental/callbacks/handlers/datadog.d.ts
experimental/callbacks/handlers/datadog.d.cts
experimental/graph_transformers/llm.cjs
experimental/graph_transformers/llm.js
experimental/graph_transformers/llm.d.ts
Expand Down
1 change: 1 addition & 0 deletions libs/langchain-community/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export const config = {
"utils/event_source_parse": "utils/event_source_parse",
"utils/cassandra": "utils/cassandra",
// experimental
"experimental/callbacks/handlers/datadog": "experimental/callbacks/handlers/datadog",
"experimental/graph_transformers/llm":
"experimental/graph_transformers/llm",
"experimental/multimodal_embeddings/googlevertexai":
Expand Down
13 changes: 13 additions & 0 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,15 @@
"import": "./utils/cassandra.js",
"require": "./utils/cassandra.cjs"
},
"./experimental/callbacks/handlers/datadog": {
"types": {
"import": "./experimental/callbacks/handlers/datadog.d.ts",
"require": "./experimental/callbacks/handlers/datadog.d.cts",
"default": "./experimental/callbacks/handlers/datadog.d.ts"
},
"import": "./experimental/callbacks/handlers/datadog.js",
"require": "./experimental/callbacks/handlers/datadog.cjs"
},
"./experimental/graph_transformers/llm": {
"types": {
"import": "./experimental/graph_transformers/llm.d.ts",
Expand Down Expand Up @@ -4038,6 +4047,10 @@
"utils/cassandra.js",
"utils/cassandra.d.ts",
"utils/cassandra.d.cts",
"experimental/callbacks/handlers/datadog.cjs",
"experimental/callbacks/handlers/datadog.js",
"experimental/callbacks/handlers/datadog.d.ts",
"experimental/callbacks/handlers/datadog.d.cts",
"experimental/graph_transformers/llm.cjs",
"experimental/graph_transformers/llm.js",
"experimental/graph_transformers/llm.d.ts",
Expand Down
Loading
Loading