OpenTelemetry
OpenTelemetry is an open-source observability framework that allows teams to collect, analyze, and visualize telemetry data.
Overview
Confident AI can recieve traces on https://otel.confident-ai.com. To export traces using the OpenTelemetry SDK, you can configure your Collector with the official open-telemetry library.
If your configration requires signal specific environment variable, set the
trace endpoint to https://otel.confident-ai.com/v1/traces.
Quickstart
Given below is the quickstart for exporting traces to Confident AI OTLP endpoint (which will then published to observatory) for different languages.
Set Environment Variables
First set your CONFIDENT_API_KEY and OTEL_EXPORTER_OTLP_ENDPOINT as an enviornment variable:
Trace your first LLM application
Python
TypeScript
Go
Ruby
C#
Install opentelemetry dependencies:
Run the following code:
Run the code:
The above example creates a new OpenTelemetry trace provider and sets OTLPSpanExporter to it so that the spans are exported to the Confident AI OTLP endpoint ONLY. If you wish to set OTLPSpanExporter to the existing OpenTelemetry trace provider, refer to the following example.
š Congratulations! You have successfully sent traces. Go to the the Observatory section on Confident AI to check it out.
Click to see native python implementation using DeepEval
DeepEval provides a native ConfidentSpanExporter that directly exports traces to Confident AI observatory.
Understanding OTEL with Confident AI
In this section, we will mainly discuss:
gen_aiattribute and event conventions- Confident AI specific conventions
- Advanced configurations
OTEL endpoints
Confident AI offers the https://otel.confident-ai.com endpoint that accepts OpenTelemetry traces in the OTLP format. Please note that Confident AI does not support GRPC for the OpenTelemetry endpoint. Please use HTTP instead.
Attributes
Confident AI adheres to the GenAI semantic convention and adds an extra layer on top of it to capture additional data about the LLM applications. Confident AI uses confident.* namespace to map specific attributes with llm tracing data model. These specific attributes always take precedence over gen_ai.* conventions and are recommended for all users that are manually instrumenting their applications.
The GenAI semantic conventions are still under development and are subject to change.
Advanced configurations
The enviornment allows you to configure where your trace belongs on Confident AI (defaulted to "development"). You can configure the enviornment and sampling rate of traces by setting the following two enviornment variables:
Trace-Level Attribute Mappings
These are the attributes specific to Confident AI traces similar to tracing features. The trace level attributes are set in the span attributes using the confident.trace.* namespace.
It is recommended to set trace attributes once in any span in a trace lifecycle. The value of the specific attribute will be updated to the latest value if set in multiple spans.
Name
The trace name is displayed in the UI. You can customize it based on your liking for better UI display using the following attribute:
"confident.trace.name"(of typestr) used for updating trace name
Input/Output
You can set trace input and output at runtime using the following attributes:
"confident.trace.input"(of typeAny) used for updating trace input"confident.trace.output"(of typeAny) used for updating trace output
Metric Collection
Metric collection allows you to run metrics on cloud and publish results to the observatory.
"confident.trace.metric_collection"(of typestr) update the name of the metric collection for the span
Test Case
LLM test case parameters can be used to unit test interactions within your LLM application. They can be set in the span as trace level attributes using the confident.trace.* namespace.
Given below is the example of running online evaluation for a span.
Make sure you have metric collection created on the platform for running online evaluation on this test case.
LLM test case attributes mapping:
"confident.trace.input"(of typestr) used for updating test case input"confident.trace.output"(of typestr) used for updating test case actual output- [Optional]
"confident.trace.expected_output"(of typestr) used for updating test case expected output - [Optional]
"confident.trace.context"(of typelist[str]) used for updating test case context - [Optional]
"confident.trace.retrieval_context"(of typelist[str]) used for updating test case retrieval context - [Optional]
"confident.trace.tools_called"(of typeToolCall) used for updating test case tools called - [Optional]
"confident.trace.expected_tools"(of typeToolCall) used for updating test case expected tools
Tags
Tags are simple string labels that make it easy to group related traces together, and cannot be applied to spans.
"confident.trace.tags"(of typelist[str]) used for updating trace tags
Metadata
Attach metadata to the trace. This information can be used for filtering, grouping, and analyzing your traces in the observatory.
"confident.trace.metadata"(of typestr) used for updating trace metadata
This attribute is a JSON string which is parsed into a dictionary.
Thread Id
A thread on Confident AI is a collection of one or more traces, letting you view full conversations ā perfect for chat apps, agents, or any multi-turn interactions.
"confident.trace.thread_id"(of typestr) used for updating trace thread id
User Id
Track user interactions by setting user id in a trace ā useful for monitoring token usage, identifying top users, and managing costs.
"confident.trace.user_id"(of typestr) used for updating trace user id
Span-Level Attribute Mappings
These are the attributes specific to Confident AI spans similar to tracing features. The span level attributes are set in the span attributes using the confident.span.* namespace.
Name
The name of the span is displayed in the UI. You can customize it based on your liking for better UI display using the following attribute:
"confident.span.name"(of typestr) used for updating span name
Input/Output
You can set span input and output at runtime using the following attributes:
"confident.span.input"(of typeAny) used for updating span input"confident.span.output"(of typeAny) used for updating span output
Metric Collection
Metric collection allows you to run metrics on cloud and publish results to the observatory.
"confident.span.metric_collection"(of typestr) update the name of the metric collection for the span
Test Case
LLM test case parameters can be used to unit test interactions within your LLM application. They can be set on the span level in any span type using the confident.span.* namespace.
Given below is the example of running online evaluation for a span.
LLM test case attributes mapping:
"confident.span.input"(of typestr) used for updating test case input"confident.span.output"(of typestr) used for updating test case actual output- [Optional]
"confident.span.expected_output"(of typestr) used for updating test case expected output - [Optional]
"confident.span.context"(of typelist[str]) used for updating test case context - [Optional]
"confident.span.retrieval_context"(of typelist[str]) used for updating test case retrieval context - [Optional]
"confident.span.tools_called"(of typeToolCall) used for updating test case tools called - [Optional]
"confident.span.expected_tools"(of typeToolCall) used for updating test case expected tools
Metadata
Metadata can be attached to the span. This information can be used for filtering, grouping, and analyzing your spans in the observatory.
"confident.span.metadata"(of typestr) used for updating span metadata
This attribute is a JSON string which is parsed into a dictionary.
Type specific attributes
Span types are optional but allow you to classify the most common types of components in LLM applications, which includes these 4 default span types:
llmagentretrievertool
You can set the span type using the following attribute:
"confident.span.type"(of typestr) used for updating span type
Span-Level Attributes for Specific Span Types
Given below are attributes for specific span types. It is recommended to set these attributes in the span attributes using the confident.{span_type}.* namespace.
Custom
This is the default span type. All the attributes that we used above with confident.span.* namespace are applicable to this span type.
LLM
To create a LLM span, set the confident.span.type to llm. After that refer to the table below for more LLM span attributes.
"confident.llm.model"(of typestr) used for updating LLM model- [Optional]
"confident.llm.cost_per_input_token"(of typefloat) used for updating cost per input token - [Optional]
"confident.llm.cost_per_output_token"(of typefloat) used for updating cost per output token - [Optional]
"confident.llm.input_token_count"(of typeint) used for updating LLM Span input token count - [Optional]
"confident.llm.output_token_count"(of typeint) used for updating LLM Span output token count
Given below is the sample code for setting attributes for LLM span type.
Agent
To create a Agent span, set the confident.span.type to agent. After that refer to the table below for more Agent span attributes.
"confident.agent.name"(of typestr) used for updating Agent span name- [Optional]
"confident.agent.available_tools"(of typelist[str]) used for updating Agent span available tools - [Optional]
"confident.agent.agent_handoffs"(of typelist[str]) used for updating Agent span agent handoffs
Given below is the sample code for setting attributes for Agent span type.
Tool
To create a Tool span, set the confident.span.type to tool. After that refer to the table below for more Tool span attributes.
"confident.tool.name"(of typestr) used for updating Tool span name- [Optional]
"confident.tool.description"(of typestr) used for updating Tool span description
Given below is the sample code for setting attributes for Tool span type.
Retriever
To create a Retriever span, set the confident.span.type to retriever. After that refer to the table below for more Retriever span attributes.
"confident.retriever.embedder"(of typestr) used for updating Retrieval span embedder model- [Optional]
"confident.retriever.top_k"(of typeint) used for updating Retrieval span top k - [Optional]
"confident.retriever.chunk_size"(of typeint) used for updating Retrieval span chunk size
Given below is the sample code for setting attributes for Retriever span type.