-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Add Python examples to Spans v2 API page #15650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ SDKs MUST NOT expose names like "segment span" (e.g. in APIs) to users and SHOUL | |
|
|
||
| SDKs' span implementations MUST at minimum implement the following span interface. | ||
|
|
||
| ```ts | ||
| ```ts {tabTitle:TypeScript} | ||
| interface Span { | ||
| private _spanId: string; | ||
|
|
||
|
|
@@ -49,6 +49,17 @@ interface Span { | |
| } | ||
| ``` | ||
|
|
||
| ```Python {tabTitle:Python} | ||
| class Span: | ||
| span_id: str | ||
|
|
||
| def set_attribute(self, key: str, value: SpanAttributeValue) -> None: ... | ||
| def set_status(self, status: Literal["ok", "error"]) -> None: ... | ||
| def get_name(self) -> str: ... | ||
| def set_name(self, name: str) -> None: ... | ||
| def get_attributes(self) -> SpanAttributes: ... | ||
| ``` | ||
|
|
||
| When implementing the span interface, consider the following guidelines: | ||
|
|
||
| - SDKs MAY implement additional APIs, such as getters/setters for properties (e.g. `span.getStatus()`), or additional methods for convenience (e.g. `Span::spanContext()`). | ||
|
|
@@ -63,7 +74,7 @@ SDKs MUST expose at least one API to start a span. SDKs MAY expose additional AP | |
|
|
||
| SDKs MUST expose a default `startSpan` API that takes options and returns a span: | ||
|
|
||
| ```ts | ||
| ```ts {tabTitle:TypeScript} | ||
| function startSpan(options: StartSpanOptions): Span; | ||
|
|
||
| interface StartSpanOptions { | ||
|
|
@@ -74,6 +85,16 @@ interface StartSpanOptions { | |
| } | ||
| ``` | ||
|
|
||
| ```Python {tabTitle:Python} | ||
| with start_span( | ||
| name, # type: str | ||
| attributes, # type: SpanAttributes | ||
| parent_span, # type: Span | ||
| active, # type: bool | ||
| ) as span: | ||
| ... | ||
| ``` | ||
|
|
||
| SDKs MUST allow specifying the following options to be passed to `startSpan`: | ||
|
|
||
| | Option | Required | Description | | ||
|
|
@@ -113,7 +134,7 @@ SDKs MAY expose additional utility APIs for users, or internal usage to access c | |
|
|
||
| ## Example | ||
|
|
||
| ```ts | ||
| ```ts {tabTitle:TypeScript} | ||
|
|
||
| const checkoutSpan = Sentry.startSpan({ name: 'on-checkout-click', attributes: { 'user.id': '123' } }) | ||
|
|
||
|
|
@@ -140,4 +161,23 @@ unrelatedSpan.end(); | |
| on('checkout-finished', ({ timestamp }) => { | ||
| checkoutSpan.end(timestamp); | ||
| }) | ||
| ``` | ||
| ``` | ||
|
|
||
| ```Python {tabTitle:Python} | ||
|
|
||
| with sentry_sdk.start_span(name="checkout", attributes={"user.id": "123"}) as checkout_span: | ||
sentrivana marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: Can If so, could we write down an example for this? I think it's fully okay to support
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ty, added in 33bad41. |
||
| with sentry_sdk.start_span(name="process-order") as process_order_span: | ||
| result = process() | ||
| process_order_span.set_attribute("order-status", result.message) | ||
|
|
||
| with sentry_sdk.start_span(name="process-payment") as process_payment_span: | ||
| try: | ||
| result = process_payment() | ||
| process_payment_span.set_attribute("order-status", result.message) | ||
| except: | ||
| process_payment_span.set_status("error") | ||
| process_payment_span.set_attribute("order-status", "error") | ||
|
|
||
| with sentry_sdk.start_span(name="log-order", parent_span=None) as unrelated_span: | ||
| log_order() | ||
| ``` | ||
sentrivana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.