Sending a Request
Currently, you are advised to use the /v1/chat/completions and /v1/completions APIs to send requests. The sampling enablement information needs to be added to the HTTP request headers of the two APIs. Currently, the format of the HTTP request headers to which the sampling enablement information can be added is as follows:
- W3C Trace Context (traceparent)
- B3 Single Header
- B3 Multiple Headers
The format of the content to be added to the HTTP request headers is described as follows.
W3C Trace Context (traceparent)
Example:
traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01
Field |
Location |
Length |
Meaning |
Required/Optional |
|---|---|---|---|---|
version |
First two bits |
2 characters |
Protocol version. Currently, the value is fixed to 00. |
Required |
trace-id |
Bits 3 to 34 |
32 characters |
Global Trace ID (16 bytes, 32 hexadecimal characters), which uniquely identifies the entire distributed tracing. |
Required |
parent-id |
Bits 36 to 51 |
16 characters |
Parent Span ID (8 bytes, 16 hexadecimal characters), which identifies the direct upstream operation. |
Required |
trace-flags |
Bits 53 to 54 |
2 characters |
Trace flag. Currently, only the least significant bits are used: 01 (sampling) and 00 (no sampling). |
Required |
B3 Single Header
Example:
b3: 0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-1-0000000000000001
Field |
Location |
Meaning |
Format |
Value Description |
Required/Optional |
|---|---|---|---|---|---|
TraceId |
Bits 1 to 32 |
Global Trace ID |
32 hexadecimal characters |
Uniquely identifies the entire distributed tracing. |
Required |
SpanId |
Bits 34 to 49 |
Current Span ID |
16 hexadecimal characters |
Uniquely identifies the current service operation. |
Required |
Sampled |
Bit 51 |
Sampling decision |
1 character |
1: enables sampling. 0: disables sampling. |
Required |
ParentSpanId |
Bits 53 to 68 |
Parent Span ID |
16 hexadecimal characters |
Identifies the direct upstream Span. |
Optional |
B3 Multiple Headers
Example:
X-B3-TraceId: 0af7651916cd43dd8448eb211c80319c X-B3-SpanId: b7ad6b7169203331 X-B3-Sampled: 1
Field |
Meaning |
Format |
Value |
Function |
Required/Optional |
|---|---|---|---|---|---|
X-B3-TraceId |
Global Trace ID |
32 hexadecimal characters (16 bytes) |
Any 32-bit hexadecimal character string |
Uniquely identifies the entire distributed tracing. All related services share the same Trace ID. |
Required |
X-B3-SpanId |
Current Span ID |
16 hexadecimal characters (8 bytes) |
Any 16-bit hexadecimal character string |
Uniquely identifies the current service operation. Each Span has an independent Span ID. |
Required |
X-B3-Sampled |
Sampling decision |
String |
1: enables sampling. 0: disables sampling. |
Determines whether to record Trace data to the backend system to minimize performance overhead. |
Required |
Executing the Send Request
Include one of the three specified HTTP request headers to send the request and enable the Trace data monitoring feature. The configured SpanId and TraceId are used as the index of each request.
The following is an example of adding the W3C Trace Context (traceparent) format to the HTTP request header:
curl http://127.0.0.1:1025/v1/chat/completions \
-X POST \
-H "Content-Type: application/json" -H "traceparent: 04-01f92f3577b34da6a3ce929d0e0e4703-00f067aa0ba90203-01" \
-d '{
"model": "qwen",
"messages": [
{"role": "user", "content": "Use Python to write a simple bubble sorting algorithm: " }
],
"max_tokens": 300,
"temperature": 0.5,
"stream": false }'