Observability
Set how many traces Chalk keeps for a function, scaling group, or sandbox with the tracing setting.
The tracing setting applies to functions,
scaling groups, and sandboxes. It sets how
many of a workload’s traces Chalk keeps. By default, functions trace every call, and scaling groups
and sandboxes keep about 1% of their traces.
The setting does not add spans to your code. To add spans and view the traces Chalk keeps, see Function and Sandbox Traces.
Functions trace every call by default. Set tracing to keep fewer, or to turn tracing off:
import chalkcompute
@chalkcompute.function(
tracing=chalkcompute.TracingPolicy(sample_rate=0.25),
)
def recommend(user_id: str) -> list[str]:
return ["item_1", "item_2"]
| Configuration | Behavior |
|---|---|
| Omitted | Trace every call. |
tracing=True | Trace every call. |
tracing=TracingPolicy(sample_rate=0.25) | Trace about 25% of calls. |
tracing=TracingPolicy(sample_rate=0.0) | Trace a call only when its caller is already being traced. |
tracing=False | Turn tracing off for the function. |
sample_rate must be between 0.0 and 1.0. Unless tracing is False, a call made from inside
a trace stays in that trace whatever the sample rate, and calls the function makes to other traced
functions join the same trace. Chalk adds tracing support to the function’s image unless tracing
is False.
The same setting applies to functions deployed with RemoteFunction.
Chalk keeps about 1% of a scaling group’s or sandbox’s traces by default. Set tracing to change
that:
import chalkcompute
img = chalkcompute.Image.debian_slim("3.12").entrypoint(
["python", "-m", "http.server", "8080"]
)
sg = chalkcompute.ScalingGroup(
image=img,
name="hello-api",
port=8080,
tracing=chalkcompute.TracingPolicy(sample_rate=0.25),
).deploy()
Sandbox takes the same tracing argument.
| Configuration | Behavior |
|---|---|
| Omitted | Keep about 1% of traces. |
tracing=True | Keep every trace. |
tracing=TracingPolicy(sample_rate=0.25) | Keep about 25% of traces. |
tracing=False | Keep no traces. |
sample_rate must be between 0.0 and 1.0. Unless tracing is False, a request that arrives
as part of a trace Chalk is already keeping stays in that trace, whatever the sample rate.
Only code instrumented with an OpenTelemetry SDK produces traces. Chalk sets the standard
OpenTelemetry environment variables in each replica or sandbox, including
OTEL_EXPORTER_OTLP_ENDPOINT, which OpenTelemetry SDKs read to find where to send traces.
tracing works by setting the OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG environment
variables. Set the sample rate either with tracing or with those variables in env, not both.
tracing has no effect. Redeploy the function, scaling group, or sandbox. The
setting applies when the workload is deployed.tracing= conflicts with env keys. The workload sets tracing and also sets
OTEL_TRACES_SAMPLER or OTEL_TRACES_SAMPLER_ARG in env. Remove one of them.