Tracing
Tracing helps you understand what happens in complex flows, such as agentic large language model (LLM) applications. Add tracing to your application to identify where issues occur. View traces on the Tracing tab of the Monitoring page in your Deployment.
OpenTelemetry concepts
Deeploy supports traces that use the OpenTelemetry protocol (OTLP) over HTTP. When working with tracing in Deeploy, keep these key concepts in mind:
- Trace: Represents the complete journey of a request as it moves through your application.
- Span: Segments of work within a trace, representing operations like API/function calls or database queries.
- Attribute: Key-value pairs providing context about a span (e.g., user ID, request parameters).
Instrumenting your application
To use tracing, instrument your application with OpenTelemetry. You can do this automatically with a framework or manually with a base OpenTelemetry software development kit (SDK). SDKs are available for many languages.
Authenticate with a Deployment token.
gRPC endpoints aren't supported. Make sure to export over HTTP by importing from opentelemetry.exporter.otlp.proto.http
.
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
resource = Resource(attributes={
"service.name": "your_service_name",
"service.version": "1.0.0"
})
# Configure the tracer provider with resource
provider = TracerProvider(resource=resource)
workspace_id = "<workspaceId>"
deployment_id = "<deploymentId>"
# OTLP exporter for sending traces to endpoint
otlp_exporter = OTLPSpanExporter(
headers={
"Authorization": "Bearer <DPTexamppletoken>"},
endpoint="https://api.app.deeploy.ml/workspaces/{workspace_id}/deployments/{deployment_id}/traces",
)
otlp_processor = SimpleSpanProcessor(otlp_exporter)
provider.add_span_processor(otlp_processor)
trace.set_tracer_provider(provider)
# ... your application
- Traces are stored for 90 days by default.
- For private cloud installations on Azure, the only supported authentication option is
clientId
andclientSecret
.
Advanced usage
Sampling strategies
For high-volume applications, configure sampling to reduce trace data volume:
from opentelemetry.sdk.trace.sampling import TraceIdRatioBased
# Sample 25% of traces
sampler = TraceIdRatioBased(0.25)
provider = TracerProvider(sampler=sampler, resource=resource)
Integrating with common libraries
OpenTelemetry provides auto-instrumentation for many popular libraries:
# Example for Flask instrumentation
from opentelemetry.instrumentation.flask import FlaskInstrumentor
app = Flask(__name__)
FlaskInstrumentor().instrument_app(app)
# Example for requests instrumentation
from opentelemetry.instrumentation.requests import RequestsInstrumentor
RequestsInstrumentor().instrument()