スパンの属性・イベント・ステータス
意味のある属性でスパンを豊かにし、時刻付きイベントを記録し、スパンのステータスを設定して、トレースを単なる時間データではなく診断に役立つものにします。
「スパンの属性・イベント・ステータス」はCoddyKit上の無料System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSystem Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Beyond Timing
A span knows its duration automatically, but raw timing is rarely enough. Enriching spans with attributes, events, and status makes traces tell a story.
Span Attributes
Attributes are key-value pairs that add context to a span, like the route handled or the number of rows returned.
span.set_attribute("http.route", "/orders/:id")
span.set_attribute("db.rows", 42)Use Conventions
Prefer standard semantic-convention keys for common data so backends understand them. Use custom keys only for domain-specific context.
standard: http.response.status_code
custom: order.tierKeep Attributes Bounded
Like metric labels, avoid high-cardinality or huge values. Do not stuff entire payloads into an attribute.
- Good: order count, region
- Bad: full request body, raw stack trace as attribute
Span Events
An event is a timestamped annotation inside a span marking something that happened at a moment, like a retry or cache miss.
span.add_event("cache.miss", { "key": "user:42" })Recording Exceptions
Exceptions are recorded as a special event capturing the type, message, and stack, so failures show up in the trace timeline.
try:
do_work()
except Exception as e:
span.record_exception(e)Span Status
Status tells whether the operation succeeded. The default is Unset; set Error on failure so backends can highlight broken spans.
span.set_status(StatusCode.ERROR, "payment declined")Status vs Recording Exceptions
Recording an exception adds detail but does not by itself mark the span failed. Always also set the status to Error.
span.record_exception(e)
span.set_status(StatusCode.ERROR)Attributes vs Events
Use attributes for facts true for the whole span; use events for things that happen at a point in time within it.
Naming Spans Well
Span names should be low cardinality, describing the operation type, not the specific instance. Put the variable part in attributes.
name: "GET /orders/:id" (good)
name: "GET /orders/48213" (bad)A Well-Formed Span
A diagnostic span has a clean name, a few bounded attributes, events for notable moments, and an accurate status.
Quick Check
Pick the correct statement about span status.
Recap
You learned to enrich spans with bounded attributes (preferring semantic conventions), to mark point-in-time moments and failures with events and record_exception, and to set status to Error explicitly. Low-cardinality span names plus rich context turn traces into real diagnostics.
AI チューターと学ぶ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「スパンの属性・イベント・ステータス」レッスンは無料ですか?
はい。「スパンの属性・イベント・ステータス」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)コースには全4レッスンが含まれています。
「スパンの属性・イベント・ステータス」で何を学びますか?
意味のある属性でスパンを豊かにし、時刻付きイベントを記録し、スパンのステータスを設定して、トレースを単なる時間データではなく診断に役立つものにします。 ブラウザで直接実行するハンズオンコードでSystem Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSystem Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「スパンの属性・イベント・ステータス」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSystem Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)レッスンでコードを書いて実行できますか?
はい。すべてのSystem Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 自動計装の手法
- 手動計装のベストプラクティス
- コンテキスト伝播とBaggage
- スパンの属性・イベント・ステータス