Repository navigation
fix: keep dropped counts on spans copied for PostHog context - #1266
Conversation
opentelemetry-sdk 1.20 and 1.21 read `.dropped` from a span's attributes, events and links during OTLP export. The copy made to add the context's distinct ID, session ID and tags held plain dicts and tuples, so export failed with AttributeError. Use the SDK's bounded collections and carry over the counts the SDK dropped under its span limits.
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
turnipdabeets
left a comment
There was a problem hiding this comment.
Thanks @fahad2932!
When a span ends inside a PostHog context (
identify_context,set_context_session,tag),with_request_contextrebuilds it as aReadableSpanto add the context values. The copy was given a plain dict for attributes and the original tuples for events and links.On opentelemetry-sdk 1.20 and 1.21, which
pyproject.tomlstill allows (opentelemetry-sdk>=1.20.0), the OTLP encoder reads.droppedfrom those collections, so export fails and the batch is lost:On newer SDKs export works, but the copy reports
dropped_attributes,dropped_eventsanddropped_linksas 0 even when the SDK dropped some under its span limits.The copy now uses
BoundedAttributesandBoundedList, without limits so nothing is truncated again, and carries the original span's dropped counts over. Spans with nothing to add are still returned untouched.💚 How did you test it?
test_processor.py: the exported copy reports dropped counts, and keeps the counts the SDK dropped underSpanLimits. Both fail without the change.pytest posthog/test/ai/otelon opentelemetry-sdk 1.20.0 and 1.45.2.pytest --timeout=30: 7332 passed, 64 skipped.ruff format --check,ruff check, andmypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter: clean.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
.droppedread, so all three are wrapped, and the dropped counts are copied so the newer-SDK case doesn't report 0.