Skip to content

docs: describe the span tree the SDK now emits - #37

Draft
apucacao wants to merge 1 commit into
ag/py-telemetry-drift-oraclefrom
ag/py-telemetry-docs
Draft

docs: describe the span tree the SDK now emits#37
apucacao wants to merge 1 commit into
ag/py-telemetry-drift-oraclefrom
ag/py-telemetry-docs

Conversation

@apucacao

@apucacao apucacao commented Aug 11, 2026

Copy link
Copy Markdown

Updates the docs to describe the span tree the SDK now emits.

README and AGENTS.md both still described one flat span per call with four attributes, which is what this SDK emitted before this stack and what neither SDK emits now. A reader following either document would have built the wrong thing.

README

  • The span tree, and the rule that tool spans are siblings of chat rather than children.
  • Why the root is the only span carrying the LaunchDarkly identity and the run total.
  • What prompt caching does to the input count. The Anthropic example is the one worth keeping in mind: the provider reports an input of 3 for a turn that processed 23,554 tokens.
  • That conversation content is off by default and how to turn it on, since that is the change most likely to surprise someone who was reading prompts off their spans.
  • That an abandoned stream is marked rather than failed.

Also fixes an install command that named a package which does not exist: launchdarkly-ai rather than launchdarkly-ai-python.

AGENTS.md

Now points at TELEMETRY-CONTRACT.md as the authority rather than restating a summary that can drift from it, and lists the shared helpers with what each one writes.

The instruction that matters most is not to hand-write a span.set_attribute for anything a helper covers: six hand-rolled copies is how these spans drifted apart in the first place.

It also records the three things a new handler author would otherwise get wrong:

  1. Cache folding belongs at the call site, not in the shared writer.
  2. Finish reasons have three mechanisms, not one.
  3. except Exception does not catch the GeneratorExit a streaming consumer triggers by breaking out of the loop.

Per-package docs

Each handler package's agents.md gets a four-line note with its span shape and a pointer to the contract, so someone opening one package sees it without reading the root document first.

Where this sits

Top of the stack. Docs only, no code.


Note

Overview
Documentation-only PR that replaces outdated “one flat span per call” telemetry guidance with the three-level span tree (invoke_agentchat {model}execute_tool {tool_name}), including that tool spans are siblings of chat, not children.

README adds user-facing coverage of root-only LaunchDarkly identity and run totals, per-turn token reporting, Anthropic-style cache folding into gen_ai.usage.input_tokens, capture_content=True on handler factories, and abandoned streaming (launchdarkly.stream.abandoned). It also corrects the OTel install line from launchdarkly-ai[otel] to launchdarkly-ai-python[otel].

AGENTS.md defers to TELEMETRY-CONTRACT.md, lists shared span helpers and what they write, and documents handler-author pitfalls: explicit parent context, call-site cache folding, default-off content, three finish-reason mechanisms, and finally cleanup for streaming (GeneratorExit).

Each Tier 1 handler package agents.md gets a short top note on span shape, spans.py, and the contract pointer.

Reviewed by Cursor Bugbot for commit d83d7be. Bugbot is set up for automated code reviews on this repo. Configure here.

@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2137167. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 2137167 to 73fa904 Compare August 11, 2026 20:43
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 73fa904. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 73fa904 to 1f5aa42 Compare August 11, 2026 21:01
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1f5aa42. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 1f5aa42 to 619c8ef Compare August 11, 2026 21:18
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 619c8ef. Configure here.

@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 619c8ef. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 619c8ef to c2a178b Compare August 12, 2026 17:23
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c2a178b. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from c2a178b to cc0eb52 Compare August 12, 2026 17:45
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit cc0eb52. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from cc0eb52 to b2b3c53 Compare August 12, 2026 18:02
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b2b3c53. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from b2b3c53 to c139584 Compare August 12, 2026 18:07
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f2cf8bc. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from f2cf8bc to 3eb47b2 Compare August 12, 2026 18:51
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3eb47b2. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 3eb47b2 to f70c1ab Compare August 12, 2026 19:09
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f70c1ab. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from f70c1ab to 6988504 Compare August 12, 2026 19:21
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6988504. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 6988504 to 6541db4 Compare August 13, 2026 00:33
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6541db4. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 6541db4 to babef9a Compare August 13, 2026 00:55
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit babef9a. Configure here.

@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from babef9a to 8c7eec5 Compare August 13, 2026 01:09
@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from babef9a to 8c7eec5 Compare August 13, 2026 01:09
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8c7eec5. Configure here.

README and AGENTS.md both still described one flat span per call with four
attributes, which is what this SDK emitted before the span work and what
neither SDK emits now. A reader following either document would have built the
wrong thing.

README gains the tree, the rule that tool spans are siblings of chat rather
than children, why the root is the only span carrying the LaunchDarkly identity
and the run total, and what prompt caching does to the input count. The
Anthropic example is the one worth keeping in mind: the provider reports an
input of 3 for a turn that processed 23,554 tokens.

It also documents that conversation content is off by default and how to turn
it on, since that is the change most likely to surprise someone who was reading
prompts off their spans.

AGENTS.md now points at TELEMETRY-CONTRACT.md as the authority rather than
restating a summary that can drift from it, and lists the shared helpers with
what each one writes. The instruction that matters most is not to hand-write a
span.set_attribute for anything a helper covers: six hand-rolled copies is how
these spans drifted apart in the first place.

It also records the three things a new handler author would otherwise get
wrong: that cache folding belongs at the call site and not in the shared
writer, that finish reasons have three mechanisms rather than one, and that
`except Exception` does not catch the GeneratorExit a streaming consumer
triggers by breaking out of the loop.

Each handler package's agents.md gets a four-line note with its span shape and
a pointer to the contract, so someone opening one package sees it without
reading the root document first.

Fixes the README's install command, which named a package that does not exist:
launchdarkly-ai rather than launchdarkly-ai-python.
@apucacao
apucacao force-pushed the ag/py-telemetry-docs branch from 8c7eec5 to d83d7be Compare August 13, 2026 01:37
@apucacao

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d83d7be. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant