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

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"]
ConfigurationBehavior
OmittedTrace every call.
tracing=TrueTrace 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=FalseTurn 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.


​
Scaling groups and sandboxes

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.

ConfigurationBehavior
OmittedKeep about 1% of traces.
tracing=TrueKeep every trace.
tracing=TracingPolicy(sample_rate=0.25)Keep about 25% of traces.
tracing=FalseKeep 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.


​
Troubleshooting

  • A change to 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.