選擇要保留哪些追蹤

閱讀約 50 分鐘,7 節 中共有 6 個範例。

版次 2026.11.2 範例於 2026年11 月 23 通過測試 80 個範例中有 80 個通過 變更內容

由 AI 翻譯。經人工以英文驗證。 我們如何製作書籍

譯自英文書,版次 2026.11.2。 閱讀原文

Labs

透過實作學習本章

完全照書中的方式執行每個範例,修改程式碼觀察結果,並在書中的程式碼與資料上嘗試你自己的想法。無須安裝,你的工作會自動儲存。約 30 秒內開啟。

完全照書中的方式執行每個範例,修改程式碼觀察結果,並在書中的程式碼與資料上嘗試你自己的想法。無須安裝,你的工作會自動儲存。由 Labs 為你執行:每月 40 小時。

在 Lab 中開啟,於新分頁開啟

正在檢查您的時數…

正在尋找您的 Lab…

於您自己的電腦,免費: 下載本書的筆記本,連同其程式碼與資料,皆取自 GitHub。

讀完本章後,你將能選擇後端要保留哪些追蹤,說明每種選擇會捨棄什麼,並能依據保留下來的追蹤推算總量,同時給出結果的區間。你會撰寫一條規則,保留工程師最需要的追蹤,並用事故當天的資料加以檢驗。

Ambrewick 為每則訊息保留一條追蹤,而第 1 章也保留了每一條。以本書每天 200 則訊息的規模來看,這很容易管理。但一個整天回應訊息的服務會寫出多得多的追蹤,而一個把所有追蹤保存一年的後端,必須為每一條付出成本。取樣器(sampler)會保留一部分追蹤,並捨棄其餘的,因此真正重要的決定是保留哪些。事故當天就顯示了這個問題。當天的錯誤很少見,而在警報之後打開追蹤的工程師,需要的是這些錯誤和處理緩慢的訊息,而不是任何一則典型訊息。若取樣器在選取追蹤時不讀取內容,它保留這些罕見追蹤的比例,就會和其他所有追蹤相同。

本章建立追蹤取樣所做的三種決定,以及只保留部分追蹤時,推算總量所需的估計方法。這裡的追蹤取樣,指的是決定後端要保留哪些追蹤。它與詞元取樣(token sampling)無關,後者是挑選模型接下來要寫出的詞。範例使用兩個已錄製的日子:沒有注入任何故障的基準日 1,以及第 9 章的事故日。兩者都錄製於錄製機器上,也就是一部 2.10 GHz 的 4 vCPU Intel Xeon,執行 Qwen3-4B-Instruct-2507,並且都在虛擬時鐘上重播。

此部分尚未翻譯,因此以英文呈現。

Head sampling decides before the trace runs

Head sampling decides whether to keep a trace when it starts, before any span has run. The kind this chapter uses keeps a fixed share by the trace ID, so it cannot know whether the message will fail and cannot aim at failures. The ratio is the share of traces kept, and the sample is keyed on the trace ID.

The SDK's ratio sampler compares the trace ID with the ratio. It reads the low 64 bits of the trace ID as a number, and it keeps the trace when that number falls below the ratio's share of the whole range (the sampler in the Python SDK, pinned here at 1.45.2). The decision depends on the ID alone, so every span of a trace agrees with the others, and the same trace gets the same answer on every run. The book's trace IDs count up from 1, and small counts all fall under any ratio above zero, so the book hashes each count to 128 bits before the sampler reads it. The specification deprecates TraceIdRatioBased in favour of ProbabilitySampler, which decides from the 56 bits of randomness that W3C Trace Context Level 2 specifies (the trace SDK specification at v1.50.0). The pinned SDK has no ProbabilitySampler, so the book uses the ratio sampler at the root.

The replay runs every message first and makes the head decision afterward. The decision is applied to the completed traces, and it is the same decision the assistant's own sampler would make at the source, because the trace ID alone settles it. The example's last lines check that claim: at each ratio it uses, a provider with the same sampler starts a root span for every trace ID of the day, and the example asserts that the two decisions agree.

head-sample-ratio.py Python 3.13.16 · bm25s 0.3.16 · mcp 2.3.0 · numpy 2.5.5 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 通過
"""Head sampling on baseline day 1: the share of messages each ratio keeps, and the rule that a larger ratio keeps everymessage a smaller one kept. The decision is the SDK's TraceIdRatioBased on each message's trace ID, as its root wouldmake it, so the same messages stay kept as the ratio grows. A live provider samples the same trace IDs at the source, andthe replayed and the live decisions must agree."""from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporterfrom lib.dayrun import run_day_tracedfrom lib.prices import PriceTablefrom lib.report import fmt_int, fmt_sharefrom lib.sampling import head_ratio, head_sample, live_provider, message_traces, only_messagesMODEL = "Qwen3-4B-Instruct-2507"DAY = "2026-12-08"                                  # baseline day 1: no injected faultsRATIOS = (0.01, 0.1, 0.5, 1.0)                      # 1.0 keeps everything, the check that the ratio is read as a sharetraces = only_messages(message_traces(run_day_traced(DAY, live=False).spans, DAY, MODEL, PriceTable()))print("messages on baseline day 1, of all messages:", fmt_int(len(traces)))kept = {}                                           # ratio -> the sequential trace IDs it keepsfor ratio in RATIOS:    kept[ratio] = {t.seq for t in head_sample(traces, ratio)}    print(f"messages kept at ratio {ratio}, of {len(traces)}:", fmt_int(len(kept[ratio])))    print(f"share of messages kept at ratio {ratio}:", fmt_share(len(kept[ratio]), len(traces)))    # The source's own decision: a provider with the same sampler makes one root per trace ID, counting from 1.    provider = live_provider(head_ratio(ratio), InMemorySpanExporter())    tracer = provider.get_tracer("ambrewick.assistant")    live = set()    for seq in range(1, len(traces) + 1):        root = tracer.start_span("invoke_agent probe")        if root.is_recording():            live.add(seq)        root.end()    differ = len(live ^ kept[ratio])    print(f"trace IDs where the replayed and the live decision differ at ratio {ratio}, of {len(traces)}:", fmt_int(differ))    assert differ == 0# A trace kept at a small ratio is kept at every larger one: the decision compares one fixed value with the ratio.assert kept[0.01] <= kept[0.1] <= kept[0.5] <= kept[1.0]assert len(kept[1.0]) == len(traces)
輸出python head-sample-ratio.py
messages on baseline day 1, of all messages: 200
messages kept at ratio 0.01, of 200: 5
share of messages kept at ratio 0.01: 2.5%
trace IDs where the replayed and the live decision differ at ratio 0.01, of 200: 0
messages kept at ratio 0.1, of 200: 21
share of messages kept at ratio 0.1: 10.5%
trace IDs where the replayed and the live decision differ at ratio 0.1, of 200: 0
messages kept at ratio 0.5, of 200: 96
share of messages kept at ratio 0.5: 48.0%
trace IDs where the replayed and the live decision differ at ratio 0.5, of 200: 0
messages kept at ratio 1.0, of 200: 200
share of messages kept at ratio 1.0: 100.0%
trace IDs where the replayed and the live decision differ at ratio 1.0, of 200: 0

A larger ratio keeps every message that a smaller one kept, and the example checks that first. At 0.1 the backend keeps 21 of the day's 200 messages. The ratio describes the share over many traces, and a single day can land a little above or below it, so the count is the day's and not the ratio's.

Working rule: Pick a head ratio only for traffic whose rare cases you can afford to lose. Run the ratio sampler at the root only, under ParentBased, and leave every other service on the default sampler or another parent-based one. The trace SDK specification recommends the ratio sampler "only for root spans", since different SDKs, and different versions of one SDK, can give inconsistent results for the same input. Print the kept share beside its count, as the example does, and never read the share as a count.

子 span 沿用根 span 的決定

一條追蹤(trace)會跨越處理程序邊界,而聯絡人伺服器就是第二個處理程序。第 4 章把追蹤的識別資訊以 traceparent 放進每個請求,該標頭的旗標之一是取樣旗標(Trace Context Level 1,本書採用的版本)。以父 span 為準的取樣(parent-based sampling)讓每個 span 都沿用其父 span 的決定。根 span 向頭部取樣器(head sampler)詢問,其下的每個 span 則讀取父 span 的旗標,而不是自行套用一個比例。這在跨處理程序時很重要,因為伺服器看不到助理設定的比例,只看得到旗標。

聯絡人伺服器本身沒有設定取樣器。它的 tracer provider 採用 SDK 的預設值,也就是 OTEL_TRACES_SAMPLER 未設定的情況,此時會依循遠端父 span 的取樣旗標:旗標已設定時,伺服器取樣該 span;旗標未設定時,伺服器就捨棄它。下列探測在來源端把助理的取樣器設為 0.5 的比例,並計算伺服器在每個根 span 之下記錄了多少 span。

parent-based-follows-root.py Python 3.13.16 · mcp 2.3.0 · numpy 2.5.5 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 通過
"""A parent-based sampler at the assistant decides each message's trace once, at its root, and the contacts server followsthat decision through the traceparent. The point rests on the server's count: no span reaches the receiver from atrace the assistant did not sample."""import jsonimport tempfilefrom collections import Counterfrom pathlib import Pathfrom opentelemetry import tracefrom opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporterfrom lib.clock import VirtualClockfrom lib.report import fmt_int, fmt_sharefrom lib.sampling import head_ratio, live_providerfrom lib.tools import LiveContactsDAY, PROBES, RATIO = "2026-12-09", 40, 0.5exporter = InMemorySpanExporter()provider = live_provider(head_ratio(RATIO), exporter)  # the assistant's provider: its roots sampled at 0.5, children followtrace.set_tracer_provider(provider)                    # the MCP client span is made by the process's global providertracer = provider.get_tracer("ambrewick.assistant")recorded = {}                                          # trace ID -> whether the assistant's root was recordedwith tempfile.TemporaryDirectory() as folder:    spans_file = Path(folder) / "contacts-spans.jsonl"  # the server writes here, and the file is read after it exits    with LiveContacts(VirtualClock(DAY), spans_file) as contacts:        for number in range(PROBES):            with tracer.start_as_current_span(f"invoke_agent probe {number}") as root:                recorded[format(root.get_span_context().trace_id, "032x")] = root.is_recording()                contacts.find("U0028", "Ana")          # one tool call, inside this root, so its traceparent carries the root's flag    server = [json.loads(line) for line in spans_file.read_text(encoding="utf-8").splitlines()]per_trace = Counter(row["trace_id"] for row in server)sampled = [t for t, yes in recorded.items() if yes]unsampled = [t for t, yes in recorded.items() if not yes]print("probes, one assistant root each:", fmt_int(PROBES))print(f"roots sampled at ratio {RATIO}, of {PROBES}:", fmt_int(len(sampled)))print(f"share of roots sampled at ratio {RATIO}:", fmt_share(len(sampled), PROBES))print("contacts server spans under sampled roots:", fmt_int(sum(per_trace[t] for t in sampled)))print("contacts server spans under unsampled roots:", fmt_int(sum(per_trace[t] for t in unsampled)))print("unsampled roots with any server span, of the unsampled:", fmt_int(sum(per_trace[t] > 0 for t in unsampled)))print("sampled roots with any server span, of the sampled:", fmt_int(sum(per_trace[t] > 0 for t in sampled)))assert all(t in recorded for t in per_trace)  # every server span belongs to a probe's traceassert not any(per_trace[t] for t in unsampled)     # the server records nothing for an unsampled traceassert all(per_trace[t] for t in sampled)           # and everything for a sampled one
輸出python parent-based-follows-root.py
probes, one assistant root each: 40
roots sampled at ratio 0.5, of 40: 19
share of roots sampled at ratio 0.5: 47.5%
contacts server spans under sampled roots: 39
contacts server spans under unsampled roots: 0
unsampled roots with any server span, of the unsampled: 0
sampled roots with any server span, of the sampled: 19
習題 11.1

為什麼未取樣的根不會產生伺服器 span

+10 則證明

探測程式印出「contacts server spans under unsampled roots: 0」。下列哪一項說明能解釋這個結果?

為什麼未取樣的根不會產生伺服器 span:選出正確的說明
在 Python 3.13.16 上執行

聯絡人伺服器沒有自行做任何決定,因此一條追蹤要麼在兩端都被記錄,要麼兩端都不記錄。在未取樣的根 span 之下,伺服器記錄了 0 個 span。在 40 個探測根 span 中,助理取樣了 19 個,而其中每一個都有伺服器 span,範例也以斷言確認了這一點。

實用原則: 只在根 span 取樣,其他每個服務都使用預設取樣器或另一個以父 span 為準的取樣器。若另一個服務自行採用不同的比例、演算法或 SDK 版本,同一條追蹤的兩半就可能各自留存,因為只有在同一比例下的兩個相同取樣器才會一致。我們不會讓伺服器擁有自己的比例。

此部分尚未翻譯,因此以英文呈現。

Tail sampling reads the whole trace

Head sampling decides before the message runs, and the failure happens while it runs. Tail sampling decides once the whole trace is in, by what it holds. The rule in this chapter keeps three kinds of trace, in this order. It keeps a trace whose message has an error, in the sense chapter 8 defines. It keeps a trace whose message ran past the latency objective from chapter 9, which is 20,000.0 ms. And it keeps a trace whose model calls cost more than the 99th percentile of baseline day 1, which is $0.000115 per message, the costly tail that chapter 6 counts. Each kept trace is kept whole, with every span from both processes, and the rule stops once its span budget is spent.

The rule is this book's own code, TailRule in lib/sampling.py, and it runs at the receiver once a trace's root has arrived. In every trace of the incident day the root is the last span to end, so a trace is whole when its root arrives. That is by end time. Spans can arrive over a network in another order, so a receiver should also wait.

The rule reads each whole trace, so the errors it keeps are the ones it found, not the ones a ratio happened to pick. The timeout window is part of this count. Chapter 9 showed that a lookup timeout writes ERROR attempts while the user still gets a reply, so those messages have an error in chapter 8's sense. The engineer needs their cause even though no user complained, and the rule keeps them for that reason.

Before the first run, make a prediction. The incident day has messages with an error, and a 10% head sample decides for each of them before anything runs. Predict how many of those messages the head sample keeps: all of them, about a tenth of them, or none. Write the number down, then run the example.

tail-rule-keeps-errors.py Python 3.13.16 · bm25s 0.3.16 · mcp 2.3.0 · numpy 2.5.5 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 通過
"""The incident day's failed messages, kept by a 10 percent head sample and by the tail rule. A message failed when a spanin its trace ends with ERROR (chapter 8). The head sample decides before anything runs, so the count it keeps is chance;the tail rule reads each whole trace and keeps every failed one. A detached root is judged as a trace of its own."""from lib.clock import NS_PER_SECONDfrom lib.dayrun import run_day_tracedfrom lib.prices import PriceTablefrom lib.report import fmt_int, fmt_ms, fmt_share, fmt_usdfrom lib.sampling import TailRule, head_sample, message_traces, only_messagesfrom lib.stats import nearest_rankMODEL = "Qwen3-4B-Instruct-2507"BASE, INCIDENT = "2026-12-08", "2026-12-09"SLOW_NS = 20 * NS_PER_SECOND                        # chapter 9's latency objective: a message over 20 s is slowprice = PriceTable()# The expensive threshold is baseline day 1's 99th percentile of message cost (nearest rank, PL-5): the incident is# judged by the day before it, not by itself.expensive = nearest_rank([t.cost for t in only_messages(message_traces(run_day_traced(BASE, live=False).spans, BASE, MODEL, price))], 99)live = run_day_traced(INCIDENT)                     # live: the contacts server runs the injected faults over stdiotraces = message_traces(live.spans + live.server, INCIDENT, MODEL, price)  # each trace whole, the server's spans includedmessages = only_messages(traces)failed = [t for t in messages if t.error]head = head_sample(messages, 0.1)kept = TailRule(keep_error=True, slow_ns=SLOW_NS, expensive=expensive, budget=sum(len(t.rows) for t in traces)).keep(traces)print("latency threshold, the 20 s objective:", fmt_ms(SLOW_NS))print("cost threshold, baseline day 1's 99th percentile per message:", fmt_usd(expensive))print("messages on the incident day:", fmt_int(len(messages)))print("detached roots, traces of their own with no message, incident day:", fmt_int(len(traces) - len(messages)))print("messages with an error, of all messages:", fmt_int(len(failed)))print("share of messages with an error:", fmt_share(len(failed), len(messages)))print(f"messages with an error kept by a 10% head sample, of {len(failed)}:", fmt_int(sum(t.error for t in head)))print("share of messages with an error kept by a 10% head sample:", fmt_share(sum(t.error for t in head), len(failed)))print(f"messages with an error kept by the tail rule, of {len(failed)}:", fmt_int(sum(t.seq in kept for t in failed)))print("share of messages with an error kept by the tail rule:", fmt_share(sum(t.seq in kept for t in failed), len(failed)))assert all(t.seq in kept for t in failed)           # the tail rule keeps every failed messageassert sum(t.error for t in head) < len(failed)     # the head sample loses most of themassert all(max(r["end_ns"] for r in t.rows if r["parent_span_id"] is None) == max(r["end_ns"] for r in t.rows)           for t in traces)                         # the root ends last, so a trace is whole when its root arrives (B-83)
輸出python tail-rule-keeps-errors.py
latency threshold, the 20 s objective: 20,000.0 ms
cost threshold, baseline day 1's 99th percentile per message: $0.000115
messages on the incident day: 60
detached roots, traces of their own with no message, incident day: 4
messages with an error, of all messages: 17
share of messages with an error: 28.3%
messages with an error kept by a 10% head sample, of 17: 2
share of messages with an error kept by a 10% head sample: 11.8%
messages with an error kept by the tail rule, of 17: 17
share of messages with an error kept by the tail rule: 100.0%
習題 11.2

為什麼前段取樣會漏掉大多數失敗

+10 則證明

第 22 行取 10% 的前段取樣,第 30 行回報該樣本保留了多少失敗的訊息。下列何者能解釋為什麼前段取樣只保留少數失敗的訊息?

為什麼前段取樣會漏掉大多數失敗:選出正確的說明
在 Python 3.13.16 上執行

The incident day has 60 messages, and 17 of them have an error.

The head sample loses most of those errors. It keeps 2 of them, which is 11.8%. The guess of about a tenth came close here, but the head sample had no way to aim at the errors, so its count was a matter of chance.

The tail rule loses none. It keeps all 17 of them.

A rule that keeps every error can still cost too much, so the book's rule also takes a budget of spans for the day. Spans are what the backend stores, and a trace with many model calls holds many of them. Next, the rule is given a budget that the incident day cannot fit whole: 120 spans against a day of 276.

tail-rule-span-budget.py Python 3.13.16 · bm25s 0.3.16 · mcp 2.3.0 · numpy 2.5.5 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 通過
"""The tail rule under a span budget on the incident day: errors first, then the slowest messages, then the costliest, eachkept whole until the budget is spent. The budget of 120 spans is below the 127 the rule would keep with none, so it hasto drop something; the point rests on every error being kept and the slow message with no error being dropped."""from lib.clock import NS_PER_SECONDfrom lib.dayrun import run_day_tracedfrom lib.prices import PriceTablefrom lib.report import fmt_int, fmt_ms, fmt_sharefrom lib.sampling import TailRule, message_traces, only_messages, retained_bytesfrom lib.stats import nearest_rankMODEL = "Qwen3-4B-Instruct-2507"BASE, INCIDENT = "2026-12-08", "2026-12-09"BUDGET, SLOW_NS = 120, 20 * NS_PER_SECONDprice = PriceTable()base = only_messages(message_traces(run_day_traced(BASE, live=False).spans, BASE, MODEL, price))expensive = nearest_rank([t.cost for t in base], 99)  # the baseline day's 99th percentile of cost, as in the last examplelive = run_day_traced(INCIDENT)                     # live: the contacts server runs the injected faults over stdiotraces = message_traces(live.spans + live.server, INCIDENT, MODEL, price)  # each trace whole, the server's rows includedmessages = only_messages(traces)spans = sum(len(t.rows) for t in messages)kept = TailRule(True, SLOW_NS, expensive, BUDGET).keep(traces)no_budget = TailRule(True, SLOW_NS, expensive, sum(len(t.rows) for t in traces)).keep(traces)kept_spans = sum(len(t.rows) for t in traces if t.seq in kept)dropped = [t for t in messages if t.duration_ns > SLOW_NS and not t.error and t.seq not in kept]print("spans in the incident day's messages:", fmt_int(spans))print("spans in messages with an error:", fmt_int(sum(len(t.rows) for t in messages if t.error)))print("span budget:", fmt_int(BUDGET))print("spans the tail rule keeps with no budget, incident day:", fmt_int(sum(len(t.rows) for t in traces if t.seq in no_budget)))print("spans kept under the budget, of all spans:", fmt_int(kept_spans))print("share of spans kept under the budget:", fmt_share(kept_spans, spans))for reason in ("error", "slow", "expensive"):    print(f"messages kept for {reason}, under the budget:", fmt_int(sum(v == reason for v in kept.values())))print("slow messages with no error, dropped for the budget:", fmt_int(len(dropped)))print("time of the slowest message dropped for the budget:", fmt_ms(max(t.duration_ns for t in dropped)))print("messages over the expensive threshold with no error or slow time, incident day:",      fmt_int(sum(t.cost > expensive and not t.error and t.duration_ns <= SLOW_NS for t in messages)))print("messages over the expensive threshold with no error or slow time, baseline day 1:",      fmt_int(sum(t.cost > expensive and not t.error and t.duration_ns <= SLOW_NS for t in base)))# Retention: bytes per message without content, in the JSON-lines export (capture is off until chapter 12).per_message, kept_bytes, day_bytes = retained_bytes(base, messages, kept)print("bytes per message without content, baseline day 1:", fmt_int(per_message))print("bytes kept under the budget, of the incident day's bytes:", fmt_share(kept_bytes, day_bytes))assert all(t.seq in kept for t in messages if t.error)  # the budget leaves every error inassert kept_spans <= BUDGETassert sum(len(t.rows) for t in traces if t.seq in no_budget) > BUDGET
輸出python tail-rule-span-budget.py
spans in the incident day's messages: 276
spans in messages with an error: 116
span budget: 120
spans the tail rule keeps with no budget, incident day: 127
spans kept under the budget, of all spans: 116
share of spans kept under the budget: 42.0%
messages kept for error, under the budget: 17
messages kept for slow, under the budget: 0
messages kept for expensive, under the budget: 0
slow messages with no error, dropped for the budget: 1
time of the slowest message dropped for the budget: 22,622.1 ms
messages over the expensive threshold with no error or slow time, incident day: 0
messages over the expensive threshold with no error or slow time, baseline day 1: 0
bytes per message without content, baseline day 1: 2,831
bytes kept under the budget, of the incident day's bytes: 42.6%
習題 11.3

預算略低於無預算時的 span 數量

+10 則證明

第 13 行設定 span 預算。請修改該行,使範例印出下方的輸出,其中只有 span 預算那一行與本書的輸出不同。 spans in the incident day's messages: 276 spans in messages with an error: 116 span budget: 126 spans the tail rule keeps with no budget, incident day: 127 spans kept under the budget, of all spans: 116 share of spans kept under the budget: 42.0% messages kept for error, under the budget: 17 messages kept for slow, under the budget: 0 messages kept for expensive, under the budget: 0 slow messages with no error, dropped for the budget: 1 time of the slowest message dropped for the budget: 22,622.1 ms messages over the expensive threshold with no error or slow time, incident day: 0 messages over the expensive threshold with no error or slow time, baseline day 1: 0 bytes per message without content, baseline day 1: 2,831 bytes kept under the budget, of the incident day's bytes: 42.6%

MODEL = "Qwen3-4B-Instruct-2507"BASE, INCIDENT = "2026-12-08", "2026-12-09"price = PriceTable()base = only_messages(message_traces(run_day_traced(BASE, live=False).spans, BASE, MODEL, price))expensive = nearest_rank([t.cost for t in base], 99)  # the baseline day's 99th percentile of cost, as in the last example

應得的輸出

spans in the incident day's messages: 276
spans in messages with an error: 116
span budget: 126
spans the tail rule keeps with no budget, incident day: 127
spans kept under the budget, of all spans: 116
share of spans kept under the budget: 42.0%
messages kept for error, under the budget: 17
messages kept for slow, under the budget: 0
messages kept for expensive, under the budget: 0
slow messages with no error, dropped for the budget: 1
time of the slowest message dropped for the budget: 22,622.1 ms
messages over the expensive threshold with no error or slow time, incident day: 0
messages over the expensive threshold with no error or slow time, baseline day 1: 0
bytes per message without content, baseline day 1: 2,831
bytes kept under the budget, of the incident day's bytes: 42.6%
在 Python 3.13.16 · bm25s 0.3.16 · duckdb 2.0.1 · httpx 0.28.1 · huggingface-hub 2.4.0 · matplotlib 3.11.2 · mcp 2.3.0 · mlflow 3.18.0 · mlflow-skinny 3.18.0 · mlflow-tracing 3.18.0 · numpy 2.5.5 · openai 3.57.0 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 · tokenizers 0.23.3 上執行

The budget keeps 116 spans, which is 42.0% of the day's. Those are the spans of the 17 messages with an error, and the rule keeps no slow message and no costly one.

Errors are ranked first, so they take their spans before anything else is considered, and the remainder of the budget is what is left for a slow message. The slow message without an error, which took 22,622.1 ms, holds more spans than that remainder, so the budget drops it. Two assertions in the code hold the rule to this: every error is kept, and the budget binds, since with no budget the rule keeps 127 spans, more than the budget allows.

The budget of 120 spans is the book's choice, not a rule of the method. It is above the spans that the errors take, so every error survives. The messages with an error hold 116 spans between them, so a budget below that would drop one of them, and the rule exists to keep them. A larger budget would also keep the slow message, at the cost of its spans.

The expensive class keeps nothing extra on either day. The number of messages above the expensive threshold with neither an error nor a slow time is 0 on the incident day and 0 on baseline day 1. Every costly message on both recorded days was also an error or a slow message, so the class does no work on them. We keep it in the rule because a costly message with neither mark is possible, and the rule should keep it when one comes. Neither recorded day shows one. The errors this rule keeps are also the traces that chapter 12 scans for personal data, so the rule also decides what that scan reads.

Working rule: Keep errors first, and set the budget above the spans they take on a day you have measured, not from a guess. Count the messages that are costly but neither erroneous nor slow before you trust a cost class, and say what a smaller budget would drop.

以樣本估計當日總量

取樣會讓 span 變少,因此以保留下來的 span 加總得到的總量會小於當日的實際總量,而取樣並不會讓計數器變少。第 6 章已說明,把 span 加總會重複計算,所以本書的總量一律讀取計數器,助理的計量器會在每次模型呼叫結束時累加計數器。第 9 章的警示也讀取同一個計量器,因此取樣絕不會讓總量或警示變少。樣本的估計值用於計數器無法做出的分項拆分,而分項拆分的品質,取決於各部分實際保留的數量。

由於每條 trace 被保留的機率相同,將頭部取樣(head sample)的總量乘以取樣比例的倒數,就能估計整體:保留的總量乘以比例的倒數,即為當日的估計值。區間為估計值加減 1.96 個標準誤,而標準誤只由取樣到的 trace 計算。尾部規則(tail rule)無論比例為何都會保留某些 trace,所以它保留的集合並非當日固定的一個比例。頭部比例與尾部規則一起運作時(見下方的決策),後端保存的是兩者的聯集,這已不是頭部取樣,因此要為每條 trace 標記其被保留的原因,並且只對頭部取樣的 trace 做縮放。本節只縮放頭部取樣。

將基準日 1 的一份 10% 樣本放大十倍,所得的估計值可以拿來和當日的完整計數及 token 計數器相比對。

estimate-totals-error.py Python 3.13.16 · bm25s 0.3.16 · mcp 2.3.0 · numpy 2.5.5 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 通過
"""Estimate baseline day 1's total tokens and cost from a 10 percent head sample, scaled by one over the ratio, with the 95percent interval (the estimate plus or minus 1.96 standard errors). The estimate is set against the full count, summed overevery message, and against the token counter's total for the day. The point is coverage: over 2,000 independent samples theinterval holds the full count in only some of them, and the printed count says how many."""from decimal import Decimalfrom opentelemetry.sdk.metrics.export import InMemoryMetricReaderfrom lib.dayrun import RELEASE, run_day_tracedfrom lib.metrics import USAGE, make_meter_provider, totalsfrom lib.prices import PriceTablefrom lib.report import fmt_int, fmt_share, fmt_usdfrom lib.sampling import draws_holding, estimate_total, head_sample, message_traces, only_messagesMODEL = "Qwen3-4B-Instruct-2507"DAY, RATIO, DRAWS, SEED = "2026-12-08", 0.1, 2000, 20261207  # SEED is PL-6's; each draw salts the trace IDs with its numberreader = InMemoryMetricReader()provider = make_meter_provider(reader, service_instance_id=f"{DAY}-metrics", service_version=RELEASE.service_version)traced = run_day_traced(DAY, live=False, meter_provider=provider)  # the assistant's live meter counts each call's tokenstraces = only_messages(message_traces(traced.spans, DAY, MODEL, PriceTable()))counter = totals(reader)counter_tokens = int(counter[USAGE["input"]]["sum"]) + int(counter[USAGE["output"]]["sum"])sample = head_sample(traces, RATIO)full_tokens = sum(t.tokens for t in traces)full_cost = sum((t.cost for t in traces), Decimal(0))print(f"messages kept at ratio {RATIO}, of {len(traces)}:", fmt_int(len(sample)))tokens, tokens_interval = estimate_total([t.tokens for t in sample], RATIO)print("full count of tokens, all messages:", fmt_int(full_tokens))print("token counter total for the day, input plus output:", fmt_int(counter_tokens))print(f"estimated tokens, ratio {RATIO}:", fmt_int(int(tokens)))print("estimate as a share of the full count, tokens:", fmt_share(tokens, full_tokens))print("interval as shares of the full count, tokens, low end:", fmt_share(tokens_interval[0], full_tokens))print("interval as shares of the full count, tokens, high end:", fmt_share(tokens_interval[1], full_tokens))cost, cost_interval = estimate_total([t.cost for t in sample], RATIO)print("full cost of the day, Qwen3-4B-Instruct-2507 at the book's rates:", fmt_usd(full_cost))print(f"estimated cost, ratio {RATIO}:", fmt_usd(cost))print("estimate as a share of the full cost:", fmt_share(cost, full_cost))print("interval as shares of the full cost, low end:", fmt_share(cost_interval[0], full_cost))print("interval as shares of the full cost, high end:", fmt_share(cost_interval[1], full_cost))assert counter_tokens == full_tokens          # the counter reads each call once, so it matches the root spansprint("samples of the same day, drawn independently:", fmt_int(DRAWS))held_tokens, held_cost = draws_holding(traces, RATIO, DRAWS, SEED)print(f"intervals that hold the full count, of {fmt_int(DRAWS)} samples at ratio {RATIO}, tokens:", fmt_int(held_tokens))print(f"intervals that hold the full count, of {fmt_int(DRAWS)} samples at ratio {RATIO}, cost:", fmt_int(held_cost))
輸出python estimate-totals-error.py
messages kept at ratio 0.1, of 200: 21
full count of tokens, all messages: 109,807
token counter total for the day, input plus output: 109,807
estimated tokens, ratio 0.1: 98,090
estimate as a share of the full count, tokens: 89.3%
interval as shares of the full count, tokens, low end: 38.7%
interval as shares of the full count, tokens, high end: 140.0%
full cost of the day, Qwen3-4B-Instruct-2507 at the book's rates: $0.007563
estimated cost, ratio 0.1: $0.005524
estimate as a share of the full cost: 73.0%
interval as shares of the full cost, low end: 29.6%
interval as shares of the full cost, high end: 116.5%
samples of the same day, drawn independently: 2,000
intervals that hold the full count, of 2,000 samples at ratio 0.1, tokens: 1,843
intervals that hold the full count, of 2,000 samples at ratio 0.1, cost: 1,854
習題 11.4

對每則訊息加總的完整計數

+10 則證明

第 24 行加總的是被保留訊息的 token 數,因此完整計數得到的是樣本的總量,而不是整天的總量。請修改第 24 行,使完整計數等於當天每一則訊息的 token 數。

counter = totals(reader)counter_tokens = int(counter[USAGE["input"]]["sum"]) + int(counter[USAGE["output"]]["sum"])sample = head_sample(traces, RATIO)full_cost = sum((t.cost for t in traces), Decimal(0))print(f"messages kept at ratio {RATIO}, of {len(traces)}:", fmt_int(len(sample)))tokens, tokens_interval = estimate_total([t.tokens for t in sample], RATIO)
在 Python 3.13.16 · bm25s 0.3.16 · duckdb 2.0.1 · httpx 0.28.1 · huggingface-hub 2.4.0 · matplotlib 3.11.2 · mcp 2.3.0 · mlflow 3.18.0 · mlflow-skinny 3.18.0 · mlflow-tracing 3.18.0 · numpy 2.5.5 · openai 3.57.0 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 · tokenizers 0.23.3 上執行

這項估計從基準日 1 的 10% 頭部取樣開始,該樣本保留了當日 21 則訊息,並將其 token 數放大十倍。完整計數為 109,807 個 token,而第 6 章讀取總量所用的當日 token 計數器,加總後也是相同的數字:109,807。

一份樣本只給出一個估計值,而區間說明的是,在這份樣本的抽取方式下,當日的完整計數可能落在哪個範圍。這個區間由樣本自身的標準誤建構而成,並不是第 7 章的 bootstrap 區間。這份樣本得出的 token 估計值為 98,090 個 token。

95% 區間從完整計數的 38.7% 延伸到 140.0%,範圍太寬而無法據以行動:只有 21 則訊息的樣本,使總量可能落在這整個範圍內的任何位置。

這個區間的涵蓋率也不如標示的水準。對同一天獨立抽取的 2,000 份樣本而言,區間包含完整計數的有 1,843 份,而這個區間原本設計的涵蓋率是 95%。

成本估計是對同一份樣本另做的加總。估計值為 $0.005524,當日的完整成本則為 $0.007563,以本書的價目表 book-2026-11-02 計價。

其區間從完整成本的 29.6% 延伸到 116.5%,同樣的樣本中有 1,854 包含完整成本。

改變比例,可以看出誤差如何取決於保留的量。

figure-sampling-error-by-ratio.py Python 3.13.16 · bm25s 0.3.16 · matplotlib 3.11.2 · mcp 2.3.0 · numpy 2.5.5 · opentelemetry-api 1.45.2 · opentelemetry-exporter-http-transport 0.66b2 · opentelemetry-exporter-otlp-common 0.66b2 · opentelemetry-exporter-otlp-proto-common 1.45.2 · opentelemetry-exporter-otlp-proto-http 1.45.2 · opentelemetry-instrumentation 0.66b2 · opentelemetry-instrumentation-genai-openai 1.3b0 · opentelemetry-proto 1.45.2 · opentelemetry-sdk 1.45.2 · opentelemetry-semantic-conventions 0.66b2 · opentelemetry-util-genai 1.3b0 · pydantic 2.14.4 通過
"""Draw the error of a head sample's estimate of baseline day 1's total tokens against the sampling ratio, with the 95 percentinterval (chapter 11, `estimating-totals-from-a-sample`). The interval narrows as the ratio rises, and at ratio 1.0 every messageis kept, so the interval has no width. The points the prose names are printed, so a reader can read them off the lines."""import mathfrom lib.dayrun import run_day_tracedfrom lib.figures import ACCENT, INK, MUTED, new_figure, savefrom lib.prices import PriceTablefrom lib.report import fmt_int, fmt_sharefrom lib.sampling import estimate_total, head_sample, message_traces, only_messagesMODEL = "Qwen3-4B-Instruct-2507"DAY = "2026-12-08"RATIOS = (0.01, 0.02, 0.05, 0.1, 0.2, 0.3, 0.5, 1.0)traces = only_messages(message_traces(run_day_traced(DAY, live=False).spans, DAY, MODEL, PriceTable()))full = sum(t.tokens for t in traces)points = []                                         # (ratio, estimate share, interval low share, interval high share)for ratio in RATIOS:    sample = head_sample(traces, ratio)    estimate, (low, high) = estimate_total([t.tokens for t in sample], ratio)    points.append((ratio, 100 * estimate / full, 100 * low / full, 100 * high / full))    if ratio in (0.01, 0.1, 0.5):        print(f"messages kept at ratio {ratio}, of {len(traces)}:", fmt_int(len(sample)))        print(f"estimate as a share of the full count, ratio {ratio}:", fmt_share(estimate, full))        print(f"interval low end as a share of the full count, ratio {ratio}:", fmt_share(low, full))        print(f"interval high end as a share of the full count, ratio {ratio}:", fmt_share(high, full))print("full count of tokens, all messages:", fmt_int(full))xs, estimate_share, low, high = zip(*points)fig, ax = new_figure(height=2.8)ax.fill_between(xs, low, high, color=MUTED, alpha=0.35, linewidth=0, label="95% interval")ax.plot(xs, estimate_share, color=ACCENT, linewidth=1.8, marker="o", markersize=3, label="estimate, head sample")ax.axhline(100, color=INK, linewidth=1, linestyle=":", label="full count")ax.set_xscale("log")ax.set_xticks(RATIOS, [f"{r:g}" for r in RATIOS])ax.set_xlabel("sampling ratio (log scale)")ax.set_ylabel("estimate, % of full count")bottom, top = float(min(low)), float(max(high))      # the axis starts at the lowest interval end, not at zeropad = 0.1 * (top - bottom)ax.set_ylim(bottom - pad, top + 2 * pad)            # headroom above the widest interval, where the legend sitsax.legend(loc="upper right", ncol=3, frameon=False)save(fig, "sampling-error-by-ratio")assert all(math.isclose(p[1], 100) for p in points if p[0] == 1.0)   # at ratio 1 every message is kept, so no errorassert all(math.isclose(p[2], p[3]) for p in points if p[0] == 1.0)  # and the interval has no width
輸出python figure-sampling-error-by-ratio.py
messages kept at ratio 0.01, of 200: 5
estimate as a share of the full count, ratio 0.01: 251.5%
interval low end as a share of the full count, ratio 0.01: -4.4%
interval high end as a share of the full count, ratio 0.01: 507.5%
messages kept at ratio 0.1, of 200: 21
estimate as a share of the full count, ratio 0.1: 89.3%
interval low end as a share of the full count, ratio 0.1: 38.7%
interval high end as a share of the full count, ratio 0.1: 140.0%
messages kept at ratio 0.5, of 200: 96
estimate as a share of the full count, ratio 0.5: 97.5%
interval low end as a share of the full count, ratio 0.5: 79.4%
interval high end as a share of the full count, ratio 0.5: 115.5%
full count of tokens, all messages: 109,807
figure: figures/sampling-error-by-ratio.svg

圖 11.1 以八種比例畫出同一個估計值,當比例趨近 1.0 時,其區間帶會收攏。在最左端,保留了 5 則訊息,估計值為完整計數的 251.5%。其區間從 -4.4% 延伸到 507.5%,因此下限低於零,這是因為保留的 trace 太少,常態近似在此失效。

比例為 0.1 時,保留了 21 則訊息,估計值為完整計數的 89.3%,區間從 38.7% 延伸到 140.0%。

比例為 0.5 時保留了 96 則訊息,估計值為完整計數的 97.5%,區間從 79.4% 延伸到 115.5%。比例為 1.0 時每則訊息都被保留,所以估計值是精確的,區間也沒有寬度,範例以斷言檢查了這一點。

0.010.020.050.10.20.30.51sampling ratio (log scale)0100200300400500600estimate, % of full count95% intervalestimate, head samplefull count
圖 11.1 頭部取樣的 token 估計值占完整計數的比例,在八種取樣比例下的結果及其 95% 區間

這個區間衡量的,是取樣在這一天所帶來的隨機性。換另一天是否會得出相同的總量,是另一個問題,這個區間並不能回答。

**實用原則:**只縮放頭部比例所保留的 trace,縮放倍數為其比例的倒數,在估計值旁印出區間,並且在同一天有計數器總量時,以它核對估計值。取樣估計值只用於計數器無法做出的分項拆分,絕不用於計數器已經記錄的總量。

保留一條追蹤的儲存成本

保留期限(retention)是指後端對各類遙測資料保存多久。Data Governance as Code針對平台的資料提出相同的概念:每一類資料要保存多久。本章只把這個概念套用在遙測資料上,也不訂定任何期限。期限取決於事故發生後工程師必須回溯多久,以及儲存的成本,這兩項都屬於負責營運後端的團隊。

期限是以位元組計價的,因此印出保留比例的尾端取樣規則範例,也一併量測了一則訊息的追蹤所佔的大小。在基準日第 1 天,一則訊息的 span 資料列在 JSON-lines 匯出中佔 2,831 位元組,此時內容擷取為關閉,且此計數只包含 span 資料列。事故當日保留下來的追蹤佔當日位元組的 42.6%,而 span 的保留比例為 42.0%。在這裡,位元組數與 span 數的變化相當接近,因此就這一天而言,span 的保留比例可以作為位元組保留比例的合理參考。

這個計數並未包含內容。內容擷取在第 12 章之前都是關閉的,該章會為一項指定的目的開啟擷取,並量測提示與回覆在這條相同的匯出路徑上增加了多少資料。因此,該位元組數只是一則訊息之追蹤大小的下限。此外,取樣只決定哪些 span 會送達後端,並不決定程序如何處理被丟棄的 span;第 12 章會說明上傳掛鉤(upload hook)如何處理那些 span 中的內容。

實用原則: 在訂定期限之前,先在自己的匯出資料上量測每則訊息的位元組數,先不含內容,再加入你打算保留的內容。把期限與它所乘上的位元組數放在一起記錄,並註明這些位元組沒有涵蓋哪些項目。

取樣在正式環境中出錯的地方

前端比例取樣(head ratio)只會依其比例行事,不會多做任何事。在平靜的一天與出現新故障的一天,它保留的預期比例相同,因為它的決定從不讀取訊息。尾端規則所保留的集合則會隨故障而變動,這也是本章同時使用兩者的原因。前端取樣仍有其用處。它會保留一份一般追蹤的樣本,使人能讀到典型的訊息,而且它的決定不需要檢視訊息。

尾端規則的兩個門檻來自本書的其他部分,而且會變動。延遲門檻是第 9 章的目標。高成本門檻是基準日成本的第 99 百分位數,若某次發行改變了成本,這個門檻也會隨之移動。因此,每次發行若改變了一則訊息的成本,就要重新讀取高成本門檻,而不是沿用最初的基準。

這條規則需要完整的追蹤,而且它只就手上的追蹤做判斷。分離的根會自行開啟一條追蹤,規則依該追蹤所含的內容來判斷它。在事故當天,範例計得 4 條這類追蹤,每一條都是在查詢逾時後、沒有目前脈絡的情況下送出的 MCP notifications/cancelled span,且每一條都被單獨判斷。該訊息的其餘部分位於另一條追蹤中,規則可能依其他理由保留或捨棄它。這項檢查只涵蓋本書追蹤的形態,正式環境中可能還有其他形態,而檢查並未顯示。

實用原則: 評斷一條規則,要看它在出問題的日子保留了什麼,而不是看平靜的一天;在發行改變了某個門檻所衡量的內容之後,要重新讀取該門檻。

此部分尚未翻譯,因此以英文呈現。

The decisions this chapter made

The decisions below follow from one fact the examples show: a sampler's share is set before the message is known, so keeping the messages an engineer needs takes a rule that reads each whole trace.

  • We keep the head ratio and the tail rule together. The head sample alone kept 2 of the 17 messages with an error, and the tail rule keeps all of them.
  • The tail rule keeps errors first, then slow messages, then costly ones, under a budget of 120 spans. The budget sits above the spans the errors take, and one below them would drop an error.
  • Every service samples with parent-based sampling, and only the root's service makes the decision. The contacts server follows the assistant's flag and runs no ratio of its own.
  • Chapter 6's rule for totals holds here. A sampled estimate, printed with its interval, is for a split the counters cannot make, and it is only as good as each part's kept count.
  • The retention period belongs to the team. We measure the bytes per message first, without content, and chapter 12 adds what content costs.

Two of these are judgements that the examples cannot settle. The budget of 120 spans is one, because it is the book's number and not a measured limit. Parent-based sampling is the other. The probe checks the SDK's default sampler on one server, and it says nothing about services that this book does not run. A reader who copies the rule should measure their own day first: the spans their errors take, the bytes per message, and the messages that are costly but neither erroneous nor slow. Only then should any number in this chapter become a setting.

What the chapter learned is narrower than a rule about sampling. A head sampler's share is fixed by the trace ID before the message runs, so only a rule that reads each whole trace keeps the messages an engineer needs. A total from the kept traces is an estimate, and it carries its interval wherever it is printed.

Working rule: Before you copy a sampling setting, run its example on a day you have recorded yourself, and keep each setting with the example that tests it.

本章,於本版次中

版次 2026.11.2範例於 2026年11 月 23 通過測試6 of 6 個範例 in this chapter pass

譯自英文書,版次 2026.11.2。

開始 Labs

本書仍可免費閱讀。

查看價格

引用本節

格式

各種格式皆引用英文原書,本譯本即依循該原書。

每種格式都會標示本版。其連結會開啟目前版次,節標題會說明該節內文最後一次變動的時間。存取日期與擷取日期即為你開啟此頁的當日。

本頁內容

第 11 章,共 12 章: 選擇要保留哪些追蹤

  1. Head sampling decides before the trace runs
  2. 子 span 沿用根 span 的決定
  3. Tail sampling reads the whole trace
  4. 以樣本估計當日總量
  5. 保留一條追蹤的儲存成本
  6. 取樣在正式環境中出錯的地方
  7. The decisions this chapter made

返回頂端所有章節