Monitor your authorization decisions, track performance, and gain insights into your D2 deployment
Standard OTLP metrics sent to your observability platform (Prometheus, Grafana, etc.)
Usage events record information that is relevant to the d2 authorization product. For the full list see the Key Metrics table below.
Control what telemetry is sent using the D2_TELEMETRY
environment variable:
off
No telemetry
metrics
OTLP only
usage
Events only
all
Everything (default)
D2 automatically configures OpenTelemetry metrics when the required libraries are installed. No crashes if exporters aren't available - telemetry gracefully degrades.
pip install opentelemetry-api opentelemetry-sdk pip install opentelemetry-exporter-otlp-proto-http
Metric | Type | Description |
---|---|---|
d2.authz.decision.total | Counter | Total authorization decisions by tool_id, result, mode |
d2.authz.decision.latency.ms | Histogram | Authorization decision latency (typically <1ms) |
d2.tool.exec.latency.ms | Histogram | Protected function execution time |
d2.tool.invocation.total | Counter | Post-authorization tool executions by tool_id, status |
d2.policy.poll.updated | Counter | Policy bundle updates from cloud |
d2.policy.bundle.age.seconds | Gauge | Age of current policy bundle |
d2.context.leak.total | Counter | Detected context leaks (security issue) |
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 export OTEL_SERVICE_NAME=my-d2-app export OTEL_RESOURCE_ATTRIBUTES=service.version=1.0.0 export D2_TELEMETRY=all
import d2 # D2 automatically configures OTLP if libraries are available await d2.configure_rbac_async() # Your protected functions will now emit metrics @d2.d2_guard("user_data") def get_user_profile(user_id: str): return {"id": user_id, "name": "John Doe"}
When D2_TOKEN
is set, the SDK sends detailed usage events to D2 Cloud for product analytics and quota management.
policy_load
- Bundle loadedauthz_decision
- Authorization checktool_invoked
- Function executioncontext_leak
- Security issuesThe D2 Cloud platform returns sampling rates for different event types to control telemetry volume:
Event Type | Default Rate | Purpose |
---|---|---|
authz_decision | 100% | Security monitoring |
tool_invoked | 100% | Usage analytics |
policy_poll_interval | 10% | Reduce noise |
missing_policy | 50% | Error detection |
D2_TOKEN
is set)D2_TELEMETRY=off
to disable all telemetryuser_id
you pass to d2.set_user()
is included as-is; hash or pseudonymise if you don’t want to send real IDspip list | grep opentelemetry
OTEL_EXPORTER_OTLP_ENDPOINT
environment variableD2_TELEMETRY
is set to metrics
or all
d2.authz.decision.latency.ms
histogramd2.policy.bundle.age.seconds
for stale policiesd2.context.leak.total
counter@clear_context
decorators on web handlersd2.clear_user_context()
in finally blockswith d2.set_user_context()
for automatic cleanup