1. Tracing Integrations: Quick Start (Auto-Instrumentation)
Implement trace logging effortlessly with our pre-built tracing integrations. These integrations offer flexibility for further customization as needed.
2. Manual Instrumentation
For applications requiring precise control over trace data, Future AGI provides OpenTelemetry (OTEL) support. This enables custom span creation and modification using the OpenTelemetry Trace API.
Implementation Guide
Step 1: System Requirements
Prerequisites:
pip install fi-instrumentation-otel
pip install traceAI-openai
Step 2: Set Environment Variables
import os
os.environ["FI_API_KEY"] = "your-futureagi-api-key"
os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
Step 3: Configuring a Tracer
Setting up an OTEL tracer typically requires complex boilerplate code. Future AGI simplifies this process with our register helper function:
from traceai_openai import OpenAIInstrumentor
from fi_instrumentation import register
# Initialize OTel using our register function
trace_provider = register(
project_type=ProjectType.EXPERIMENT,
project_name="FUTURE_AGI",
project_version_name="openai-exp",
)
Step 4: Span Implementation
When using our Auto-Instrumenters, span creation is handled automatically. You can further customize these spans as needed.
OpenAIInstrumentor().instrument(tracer_provider=trace_provider)
For complete control over spans you can use manual instrumentation:
from opentelemetry import trace
trace.set_tracer_provider(trace_provider)
tracer = trace.get_tracer(__name__)
Next we create spans by starting spans and defining our name and other attributes:
def process_operation():
with tracer.start_as_current_span("span-name") as span:
# Execute operations tracked by 'span'
print("doing some work...")
# When the 'with' block goes out of scope, 'span' is automatically closed
You can also use start_span to create a span without making it the current span. This is usually done to track concurrent or asynchronous operations.
Implementing Nested Spans
Track sub-operations within larger operations by creating hierarchical span relationships:
def process_operation():
with tracer.start_as_current_span("parent") as parent:
# Execute parent-level operations
print("doing some work...")
# Create nested span for sub-operations
with tracer.start_as_current_span("child") as child:
# Execute child-level operations
print("doing some nested work...")
# Child span closes automatically when it's out of scope
In our platform child
span appears as a nested component under the parent
span.
Decorator Implementation
@tracer.start_as_current_span("process_operation")
def process_operation():
print("doing some work...")
Use of the decorator is equivalent to creating the span inside process_operation()
and ending it when process_operation()
is finished.
To use the decorator, you must have a tracer instance in scope for your function declaration.
Step 1: System Requirements
Prerequisites:
pip install fi-instrumentation-otel
pip install traceAI-openai
Step 2: Set Environment Variables
import os
os.environ["FI_API_KEY"] = "your-futureagi-api-key"
os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
Step 3: Configuring a Tracer
Setting up an OTEL tracer typically requires complex boilerplate code. Future AGI simplifies this process with our register helper function:
from traceai_openai import OpenAIInstrumentor
from fi_instrumentation import register
# Initialize OTel using our register function
trace_provider = register(
project_type=ProjectType.EXPERIMENT,
project_name="FUTURE_AGI",
project_version_name="openai-exp",
)
Step 4: Span Implementation
When using our Auto-Instrumenters, span creation is handled automatically. You can further customize these spans as needed.
OpenAIInstrumentor().instrument(tracer_provider=trace_provider)
For complete control over spans you can use manual instrumentation:
from opentelemetry import trace
trace.set_tracer_provider(trace_provider)
tracer = trace.get_tracer(__name__)
Next we create spans by starting spans and defining our name and other attributes:
def process_operation():
with tracer.start_as_current_span("span-name") as span:
# Execute operations tracked by 'span'
print("doing some work...")
# When the 'with' block goes out of scope, 'span' is automatically closed
You can also use start_span to create a span without making it the current span. This is usually done to track concurrent or asynchronous operations.
Implementing Nested Spans
Track sub-operations within larger operations by creating hierarchical span relationships:
def process_operation():
with tracer.start_as_current_span("parent") as parent:
# Execute parent-level operations
print("doing some work...")
# Create nested span for sub-operations
with tracer.start_as_current_span("child") as child:
# Execute child-level operations
print("doing some nested work...")
# Child span closes automatically when it's out of scope
In our platform child
span appears as a nested component under the parent
span.
Decorator Implementation
@tracer.start_as_current_span("process_operation")
def process_operation():
print("doing some work...")
Use of the decorator is equivalent to creating the span inside process_operation()
and ending it when process_operation()
is finished.
To use the decorator, you must have a tracer instance in scope for your function declaration.
Step 1: System Requirements
Prerequisites:
npm install @traceai/openai
Step 2: Set Environment Variables
process.env.FI_API_KEY = FI_API_KEY;
process.env.FI_SECRET_KEY = FI_SECRET_KEY;
Step 3: Configuring a Tracer
const { register, ProjectType } = require("@traceai/fi-core");
const traceProvider = register({
project_type: ProjectType.OBSERVE,
project_name: "FUTURE_AGI",
session_name: "chat-bot"
});
Step 4: Span Implementation
When using our Auto-Instrumenters, span creation is handled automatically. You can further customize these spans as needed.
const { OpenAIInstrumentation } = require("@traceai/openai");
const openaiInstrumentation = new OpenAIInstrumentation({});
registerInstrumentations({
instrumentations: [openaiInstrumentation],
tracerProvider: tracerProvider,
});
For complete control over spans you can use manual instrumentation:
const { trace, context } = 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");
// Activate a context manager for consistent context propagation
context.setGlobalContextManager(new AsyncLocalStorageContextManager());
// Initialize and get a tracer using our register function
const traceProvider = register({
project_type: ProjectType.OBSERVE,
project_name: "FUTURE_AGI",
session_name: "chat-bot"
});
const tracer = traceProvider.getTracer("manual-instrumentation-example");
Next we create spans by starting spans and defining our name and other attributes:
function processOperation() {
const q1 = () => tracer.startActiveSpan('processOperation', (span) => {
span.setAttribute('operation', 'processOperation');
span.end();
});
const q2 = () => tracer.startActiveSpan('processChildOperation', (span) => {
span.setAttribute('operation', 'processChildOperation');
span.end();
});
q1();
q2();
}