Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/references/production_request_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ This section explains how to configure the request tracing and export the trace
0: disable tracing
1: Trace important slices
2: Trace all slices except nested ones
3: Trace all slices
3: Trace all slices (default)
```
The trace level can be dynamically set via HTTP API, for example:
**At startup** — set `SGLANG_TRACE_LEVEL` before launching the server:
```bash
SGLANG_TRACE_LEVEL=2 python -m sglang.launch_server --enable-trace --otlp-traces-endpoint 0.0.0.0:4317 <other options>
```

**At runtime** — dynamically adjust via HTTP API without restarting:
```bash
curl http://0.0.0.0:30000/set_trace_level?level=2
```
Expand Down
2 changes: 1 addition & 1 deletion python/sglang/srt/observability/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
_trace_context_propagator = None
tracer: Optional[trace.Tracer] = None

global_trace_level = 3
global_trace_level = get_int_env_var("SGLANG_TRACE_LEVEL", 3)

TRACE_HEADERS = ["traceparent", "tracestate"]

Expand Down
9 changes: 9 additions & 0 deletions test/registered/unit/observability/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def test_set_global_trace_level(self):
self.assertEqual(mod.global_trace_level, 5)
mod.global_trace_level = orig

def test_global_trace_level_env_var(self):
import importlib

with patch.dict(os.environ, {"SGLANG_TRACE_LEVEL": "2"}):
importlib.reload(mod)
self.assertEqual(mod.global_trace_level, 2)
importlib.reload(mod) # restore default (SGLANG_TRACE_LEVEL unset → 3)
self.assertEqual(mod.global_trace_level, 3)

def test_get_global_tracing_enabled(self):
self.assertEqual(get_global_tracing_enabled(), mod.opentelemetry_initialized)

Expand Down
Loading