Introduction
Evaluation
- Overview
- Quickstart
- Future AGI Models
- Concept
- How To
- Eval Definition
Dataset
- Overview
- Concept
- Adding Dataset
- Create Dynamic Column
- Add Annotations
- Change Column Type
- Create Static Column
- Create Synthetic Data
- Experimentation
Tracing
- Overview
- Concept
- Instrumentation ( Auto )
- Manual Tracing
- Implementing Tracing
- Instrument with traceAI Helpers
- Get Current Tracer and Span
- Enriching Spans with Attributes, Metadata, and Tags
- Logging Prompt Templates & Variables
- Integrate Events, Exceptions, and Status into Spans
- Set Session ID and User ID
- Tool Spans Creation
- Mask Span Attributes
- Advanced Tracing (OTEL)
- FI Semantic Conventions
- In-line Evaluations
MCP
Admin & Settings
Manual Tracing
Get Current Tracer and Span
Sometimes it’s helpful to access whatever the current span is at a point in time so that you can enrich it with more data.
Copy
Ask AI
from opentelemetry import trace
current_span = trace.get_current_span()
# enrich 'current_span' with some information
current_span.set_attribute("example.attribute1", "value1")
current_span.set_attribute("example.attribute2", 123)
current_span.set_attribute("example.attribute3", True)
Copy
Ask AI
from opentelemetry import trace
current_span = trace.get_current_span()
# enrich 'current_span' with some information
current_span.set_attribute("example.attribute1", "value1")
current_span.set_attribute("example.attribute2", 123)
current_span.set_attribute("example.attribute3", True)
Copy
Ask AI
import { trace, context } from "@opentelemetry/api";
const currentSpan = trace.getSpan(context.active());
if (currentSpan) {
currentSpan.setAttribute("example.attribute1", "value1");
currentSpan.setAttribute("example.attribute2", 123);
currentSpan.setAttribute("example.attribute3", true);
}
Get Current Tracer
Let’s explore how to work with tracers - the core components for span creation in OpenTelemetry.
Copy
Ask AI
from opentelemetry import trace
# Assuming SpanAttributes, FiSpanKindValues, ToolCallAttributes,
# function_call_name, and arguments variables are defined externally.
tracer = trace.get_tracer(__name__)
# Start a new span for the tool function handling
with tracer.start_as_current_span("HandleFunctionCall", attributes={
SpanAttributes.FI_SPAN_KIND: FiSpanKindValues.TOOL.value,
ToolCallAttributes.TOOL_CALL_FUNCTION_NAME: function_call_name,
ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON: str(arguments),
SpanAttributes.INPUT_VALUE: function_call_name
}) as span:
pass
Copy
Ask AI
from opentelemetry import trace
# Assuming SpanAttributes, FiSpanKindValues, ToolCallAttributes,
# function_call_name, and arguments variables are defined externally.
tracer = trace.get_tracer(__name__)
# Start a new span for the tool function handling
with tracer.start_as_current_span("HandleFunctionCall", attributes={
SpanAttributes.FI_SPAN_KIND: FiSpanKindValues.TOOL.value,
ToolCallAttributes.TOOL_CALL_FUNCTION_NAME: function_call_name,
ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON: str(arguments),
SpanAttributes.INPUT_VALUE: function_call_name
}) as span:
pass
Copy
Ask AI
const { trace, context, SpanStatusCode } = require("@opentelemetry/api");
const { AsyncLocalStorageContextManager } = require("@opentelemetry/context-async-hooks");
const { register } = require("@traceai/fi-core");
const { ProjectType } = require("@traceai/fi-core");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const tracerProvider = register({
projectName: "manual-instrumentation-example",
projectType: ProjectType.OBSERVE,
sessionName: "manual-instrumentation-example-session"
});
const tracer = tracerProvider.getTracer("manual-instrumentation-example");
tracer.startActiveSpan("HandleFunctionCall", {
attributes: {
"fi.span.kind": "tool",
"tool.call.function.name": functionCallName,
"tool.call.function.arguments_json": JSON.stringify(receivedArguments),
"input.value": functionCallName
}
}, (span) => {
try {
span.setStatus({ code: SpanStatusCode.OK });
} catch (error) {
span.recordException(error);
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
throw error;
} finally {
span.end();
}
});
On this page
Assistant
Responses are generated using AI and may contain mistakes.