ch16_observability

show:
mock turns=0 · messages=0 · recorded from different source (d27ca046ef7c ≠ 0359f58792cd)
live turns=0 · messages=0
scenario a_real_otel_span_carries_the_gen_ai_attributes
scenario a_real_otel_span_carries_the_gen_ai_attributes · 3.3ms
turn 1 · 2.1ms · responded with: hello.
model mock · 2.1ms · responded with: hello.
context sent — 1 message(s)
rolecontent
[0]humanSay hello.
context ignored by the mock model {"messages": 1, "roles": ["human"]}
reply
rolecontent
[0]aihello.
otel_span_exported open file {"path": "out/ch16_observability/a_real_otel_span_carries_the_gen_ai_attributes/spans.jsonl"}
attributes_used_real_constants {"attribute_keys": ["gen_ai.system", "gen_ai.request.model"], "reply": "hello.", "usage_present": false}
scenario a_real_otel_span_carries_the_gen_ai_attributes · 1090.5ms
turn 1 · 1089.0ms · 33 in / 55 out · responded with: Hello! 👋 How can<ds_safety>[用户未成年]否 [分类]其他 [判定]用户仅请求打招呼,模型回应友好问候,内容不涉及任何政治或色情元素。 [规则]无</ds... (12 more characters)
model live · 1088.9ms (model provider 910.4 · library 178.5) · 33 in / 55 out · responded with: Hello! 👋 How can<ds_safety>[用户未成年]否 [分类]其他 [判定]用户仅请求打招呼,模型回应友好问候,内容不涉及任何政治或色情元素。 [规则]无</ds... (12 more characters)
context sent — 1 message(s)
rolecontent
[0]humanSay hello.
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (7)
temperature, max_tokens, top_p, stop, seed, tools, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length93
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "Say hello.",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:51 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 8b9292a3a907c0814dfd42d54fb3ab62.cloudfront.net (CloudFront)
x-amz-cf-id8qgyY8erSJN4m-JsrLiYKW-ViROi_DUim2JACYXVzpav9YR_sOjTog==
x-amz-cf-popDEN53-P4
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-idc137b309f1cd43505e60733e1bae006e
{
  "id": "f7ae2863-8d90-412e-a774-30b9a11ea9a1",
  "object": "chat.completion",
  "created": 1789336371,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! \ud83d\udc4b How can<ds_safety>[\u7528\u6237\u672a\u6210\u5e74]\u5426\n[\u5206\u7c7b]\u5176\u4ed6\n[\u5224\u5b9a]\u7528\u6237\u4ec5\u8bf7\u6c42\u6253\u62db\u547c\uff0c\u6a21\u578b\u56de\u5e94\u53cb\u597d\u95ee\u5019\uff0c\u5185\u5bb9\u4e0d\u6d89\u53ca\u4efb\u4f55\u653f\u6cbb\u6216\u8272\u60c5\u5143\u7d20\u3002\n[\u89c4\u5219]\u65e0</ds_safety>Safe",
        "reasoning_content": ""
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 33,
    "completion_tokens": 55,
    "total_tokens": 88,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "prompt_cache_hit_tokens": 0,
    "prompt_cache_miss_tokens": 33
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]aiHello! 👋 How can<ds_safety>[用户未成年]否 [分类]其他 [判定]用户仅请求打招呼,模型回应友好问候,内容不涉及任何政治或色情元素。 [规则]无</ds_safety>Safe
otel_span_exported open file {"path": "out/ch16_observability/a_real_otel_span_carries_the_gen_ai_attributes/spans.jsonl"}
attributes_used_real_constants {"attribute_keys": ["gen_ai.system", "gen_ai.request.model"], "reply": "Hello! \ud83d\udc4b How can<ds_safety>[\u7528\u6237\u672a\u6210\u5e74]\u5426\n[\u5206\u7c7b]\u5176\u4ed6\n[\u5224\u5b9a]\u7528\u6237\u4ec5\u8bf7\u6c42\u6253\u62db\u547c\uff0c\u6a21\u578b\u56de\u5e94\u53cb\u597d\u95ee\u5019\uff0c\u5185\u5bb9\u4e0d\u6d89\u53ca\u4efb\u4f55\u653f\u6cbb\u6216\u8272\u60c5\u5143\u7d20\u3002\n[\u89c4\u5219]\u65e0</ds_safety>Safe", "usage_present": true}
scenario otel_nests_spans_via_contextvars_the_same_way_our_stack_does
scenario otel_nests_spans_via_contextvars_the_same_way_our_stack_does · 1.7ms
turn 1 · 1.1ms · asked for: check_order
model mock · 0.7ms · asked for: check_order
context sent — 1 message(s)
rolecontent
[0]humanWhat's the status of A100?
declared tools (1)
tooldescriptionschema
check_orderCheck the status of an order by id.{"description": "Check the status of an order by id.", "properties": {"order_id": {"title": "Order Id", "type": "string"}}, "required": ["order_id"], "title": "check_order", "type": "object"}
tools declared to the mock model {"names": ["check_order"], "consulted": false}
context ignored by the mock model {"messages": 1, "roles": ["human"]}
reply
rolecontent
[0]ai
check_order({"order_id": "A100"})
tool check_order · 0.2ms · given: order_id=A100 · returned: order A100: shipped
args {"order_id": "A100"}
result {"value": "order A100: shipped"}
otel_spans_exported open file {"path": "out/ch16_observability/otel_nests_spans_via_contextvars_the_same_way_our_stack_does/spans.jsonl"}
the_chain_matches_our_own_stacks_nesting {"tool_parent_is_model": true, "model_parent_is_scenario": true, "scenario_has_no_parent": true, "all_spans_share_one_trace_id": true}
scenario otel_nests_spans_via_contextvars_the_same_way_our_stack_does · 1124.9ms
turn 1 · 1123.5ms · 300 in / 67 out · asked for: check_order · responded with: I'll look that up for you.
model live · 1121.9ms (model provider 1110.3 · library 11.5) · 300 in / 67 out · asked for: check_order · responded with: I'll look that up for you.
context sent — 1 message(s)
rolecontent
[0]humanWhat's the status of A100?
declared tools (1)
tooldescriptionschema
check_orderCheck the status of an order by id.{"description": "Check the status of an order by id.", "properties": {"order_id": {"title": "Order Id", "type": "string"}}, "required": ["order_id"], "title": "check_order", "type": "object"}
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (6)
temperature, max_tokens, top_p, stop, seed, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length324
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "What's the status of A100?",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "check_order",
        "description": "Check the status of an order by id.",
        "parameters": {
          "properties": {
            "order_id": {
              "type": "string"
            }
          },
          "required": [
            "order_id"
          ],
          "type": "object"
        }
      }
    }
  ]
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:52 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 8b9292a3a907c0814dfd42d54fb3ab62.cloudfront.net (CloudFront)
x-amz-cf-idNrYEmyD_X9k5nhYIFz7buoqNA_FPuyDUO5cc0jwrusUIWXLp0Skd8w==
x-amz-cf-popDEN53-P4
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id40726a128f5177e3761ace776d21259f
{
  "id": "3b4d656f-2d73-4174-9767-b109fd59a014",
  "object": "chat.completion",
  "created": 1789336371,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I'll look that up for you.",
        "reasoning_content": "The user asks about order A100. I should call check_order with order_id \"A100\".",
        "tool_calls": [
          {
            "index": 0,
            "id": "call_00_A3L486S0xJUAymRKtxPF0222",
            "type": "function",
            "function": {
              "name": "check_order",
              "arguments": "{\"order_id\": \"A100\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 300,
    "completion_tokens": 67,
    "total_tokens": 367,
    "prompt_tokens_details": {
      "cached_tokens": 128
    },
    "completion_tokens_details": {
      "reasoning_tokens": 20
    },
    "prompt_cache_hit_tokens": 128,
    "prompt_cache_miss_tokens": 172
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]aiI'll look that up for you.
check_order({"order_id": "A100"})
tool check_order · 0.9ms · given: order_id=A100 · returned: order A100: shipped
args {"order_id": "A100"}
result {"value": "order A100: shipped"}
otel_spans_exported open file {"path": "out/ch16_observability/otel_nests_spans_via_contextvars_the_same_way_our_stack_does/spans.jsonl"}
the_chain_matches_our_own_stacks_nesting {"tool_parent_is_model": true, "model_parent_is_scenario": true, "scenario_has_no_parent": true, "all_spans_share_one_trace_id": true}
scenario a_broken_span_exporter_cannot_break_the_call
scenario a_broken_span_exporter_cannot_break_the_call · 1.1ms
turn 1 · 0.2ms · responded with: fine, despite the exporter.
model mock · 0.2ms · responded with: fine, despite the exporter.
context sent — 1 message(s)
rolecontent
[0]humango
context ignored by the mock model {"messages": 1, "roles": ["human"]}
reply
rolecontent
[0]aifine, despite the exporter.
the_call_completed_despite_the_broken_exporter {"raised": false, "reply": "fine, despite the exporter."}
scenario a_broken_span_exporter_cannot_break_the_call · 2416.9ms
turn 1 · 2414.4ms · 31 in / 351 out · responded with: I’m ready — but I need a bit more context. Did you mean: - **“Go ahead”** with something? ... (136 more characters)
model live · 2414.3ms (model provider 2403.8 · library 10.5) · 31 in / 351 out · responded with: I’m ready — but I need a bit more context. Did you mean: - **“Go ahead”** with something? ... (136 more characters)
context sent — 1 message(s)
rolecontent
[0]humango
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (7)
temperature, max_tokens, top_p, stop, seed, tools, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length85
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "go",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:53 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 730d0b7e5f5de3b777d629325ecdb89c.cloudfront.net (CloudFront)
x-amz-cf-idtWXePa3fxGrsU0SJ-y_iLd9ElopVoZ1n--KyylU7DCWhxCXhd4FgPQ==
x-amz-cf-popDEN52-P3
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id74fe8c9cb49b43d5ea2dfb65453b6687
{
  "id": "0098f76e-3586-45f8-86c5-217da295d4dd",
  "object": "chat.completion",
  "created": 1789336373,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I\u2019m ready \u2014 but I need a bit more context. Did you mean:\n\n- **\u201cGo ahead\u201d** with something? If so, tell me the task.\n- **Play the game of Go**? If so, pick a board size (9\u00d79, 13\u00d713, or 19\u00d719) and whether you want Black or White.",
        "reasoning_content": "We need answer to \"go\" likely user wants play go? Ambiguous. Need infer. They said \"go\" maybe asking game? We need respond. Could be command to proceed? We need ask clarification? The instruction? We are assistant. The user just said \"go\". We need maybe initiate? In chat, \"go\" might mean \"start\" or \"continue\". We have no context. Could ask what they'd like. But maybe they want to play Go (board game)? The word \"go\" could mean the game Go. Need decide. Usually if user says \"go\" single word, maybe wants assistant to \"go\" i.e., proceed with something. But no prior context. We should respond asking for clarification: \"Sure\u2014what would you like me to do?\" Or if they mean the game Go, offer to play. Need be helpful.\n\nMaybe we can say: \"I\u2019m ready. Do you want to play Go (the board game), or should I continue with something?\" That covers ambiguity. Desired oververbosity 5, but simple. Since no context, best ask clarification. Could mention if you meant the game, I can play, you can choose board size, black/white. If you meant \"go ahead\", tell me what task.\n\nWe need final. Ensure no analysis. final concise. "
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 31,
    "completion_tokens": 351,
    "total_tokens": 382,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 275
    },
    "prompt_cache_hit_tokens": 0,
    "prompt_cache_miss_tokens": 31
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]aiI’m ready — but I need a bit more context. Did you mean: - **“Go ahead”** with something? If so, tell me the task. - **Play the game of Go**? If so, pick a board size (9×9, 13×13, or 19×19) and whether you want Black or White.
the_call_completed_despite_the_broken_exporter {"raised": false, "reply": "I\u2019m ready \u2014 but I need a bit more context. Did you mean:\n\n- **\u201cGo ahead\u201d** with something? If so, tell me the task.\n- **Play the game of Go**? If so, pick a board size (9\u00d79, 13\u00d713, or 19\u00d719) and whether you want Black or White."}
scenario usage_and_reasoning_tokens_map_to_the_spec
scenario usage_and_reasoning_tokens_map_to_the_spec · 0.7ms
turn 1 · 0.2ms · responded with: A short reply, to keep reasoning tokens visible.
model mock · 0.2ms · responded with: A short reply, to keep reasoning tokens visible.
context sent — 1 message(s)
rolecontent
[0]humanExplain briefly why the sky is blue.
context ignored by the mock model {"messages": 1, "roles": ["human"]}
reply
rolecontent
[0]aiA short reply, to keep reasoning tokens visible.
otel_span_exported open file {"path": "out/ch16_observability/usage_and_reasoning_tokens_map_to_the_spec/spans.jsonl"}
usage_mapped_under_mock_only_when_present {"usage_present": false, "usage": null}
scenario usage_and_reasoning_tokens_map_to_the_spec · 2093.5ms
turn 1 · 2092.7ms · 38 in / 184 out · responded with: The sky looks blue because air molecules scatter sunlight, especially the shorter blue wav... (213 more characters)
model live · 2092.6ms (model provider 2084.3 · library 8.3) · 38 in / 184 out · responded with: The sky looks blue because air molecules scatter sunlight, especially the shorter blue wav... (213 more characters)
context sent — 1 message(s)
rolecontent
[0]humanExplain briefly why the sky is blue.
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (7)
temperature, max_tokens, top_p, stop, seed, tools, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length119
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "Explain briefly why the sky is blue.",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:55 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 9d80875aac84212e41917c232a682a8a.cloudfront.net (CloudFront)
x-amz-cf-idIYqNnTfBqmtSoTxFbcXqbvLgPMSigsi609gVdbUc6m6uDtipb-MmiA==
x-amz-cf-popDEN53-P6
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-idc3faf835dd5ae40d61e4ae9482bde9a0
{
  "id": "8d475f83-8529-4812-89f5-241828554e36",
  "object": "chat.completion",
  "created": 1789336375,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The sky looks blue because air molecules scatter sunlight, especially the shorter blue wavelengths, much more strongly than longer red wavelengths (Rayleigh scattering). This scattered blue light reaches your eyes from all across the sky, so you see a blue \u201csky\u201d rather than just the Sun\u2019s direct light.",
        "reasoning_content": "We need answer brief. Need explain Rayleigh scattering. Need maybe mention sunlight contains all colors, shorter blue wavelengths scattered more by air molecules, so blue reaches eyes from all directions. At sunset red because longer path. Need concise. Ensure no inaccuracies: sky blue due to Rayleigh scattering; blue light scattered more efficiently inversely fourth power wavelength. Violet scattered more but eyes less sensitive and some absorbed, plus sun emits more blue? Actually sky appears blue not violet due to combination of Rayleigh scattering, lower sensitivity of human cones to violet, and absorption by ozone maybe. Keep brief. Final perhaps 2-3 sentences. "
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 38,
    "completion_tokens": 184,
    "total_tokens": 222,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 124
    },
    "prompt_cache_hit_tokens": 0,
    "prompt_cache_miss_tokens": 38
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]aiThe sky looks blue because air molecules scatter sunlight, especially the shorter blue wavelengths, much more strongly than longer red wavelengths (Rayleigh scattering). This scattered blue light reaches your eyes from all across the sky, so you see a blue “sky” rather than just the Sun’s direct light.
otel_span_exported open file {"path": "out/ch16_observability/usage_and_reasoning_tokens_map_to_the_spec/spans.jsonl"}
usage_mapped_under_mock_only_when_present {"usage_present": true, "usage": {"input_tokens": 38, "output_tokens": 184, "total_tokens": 222, "input_token_details": {"cache_read": 0}, "output_token_details": {"reasoning": 124}}}