sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Better new integration guide in CONTRIBUTING.md

Open sentrivana opened this issue 2 weeks ago • 2 comments

Write a better guide on how to write a new SDK integration. Mention:

  • relying on get_current_span() is brittle, carry the reference to the actual span around if possible
  • scope isolation
  • ...

From @constantinius (https://github.com/getsentry/sentry-python/issues/5177#issuecomment-3606430736):

  • get_start_span_function(): transaction vs spans discussion (might be absolved by span-first in the future). For invoke agent spans we tend to use transactions, when we are not already in a transaction. So use sentry_sdk.ai.utils.get_start_span_function for invoke_agent spans
  • Storing context: If there is a context object, we tend to store our Sentry specific context (current span, agent name etc) there. Otherwise, we use ContextVars, but that requires delicate handling (copying lists if we have a step)
  • Nested integrations: there's the concept of higher level and lower level integrations (e.g: OpenAI Agents vs OpenAI), which may result in double-reporting of (usually) chat spans, unless explicitly handled. We have the concept of exclusive integrations now.
  • many of the span attributes can be used on invoke_agent or chat or other spans (token usage, system/model, agent name especially). It makes sense to have some common facilities to allow for DRY code.
  • We should really come up with a list of necessary span attributes and what is the common way to express e.g a system prompt (is it part of the request messages? or shall we use the system.message one)

sentrivana avatar Dec 01 '25 10:12 sentrivana