Skip to content
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

Replaced all uses of description with name for start_span #11332

Open
wants to merge 4 commits into
base: antonpirker/python/custom-tracing-information
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sentry.init(...)

openai = OpenAI()

@ai_track(description="My AI pipeline")
@ai_track("My AI pipeline")
def invoke_pipeline():
result = openai.chat.completions.create(
model="some-model", messages=[{"role": "system", "content": "hello"}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ def eat_slice(slice):
def eat_pizza(pizza):
with sentry_sdk.start_transaction(op="task", name="Eat Pizza"):
while pizza.slices > 0:
with sentry_sdk.start_span(description="Eat Slice"):
with sentry_sdk.start_span(name="Eat Slice"):
eat_slice(pizza.slices.pop())
```

<Alert title="Changed in 2.15.0" level="info">

The parameter `name` in `start_span()` used to be called `description`. In version 2.15.0 `description` was deprecated and from 2.15.0 on, only `name` should be used. `description` will be removed in `3.0.0`.

</Alert>

### Using a Decorator

```python
Expand Down Expand Up @@ -88,10 +94,16 @@ def eat_slice(slice):
def eat_pizza(pizza):
with sentry_sdk.start_transaction(op="task", name="Eat Pizza"):
while pizza.slices > 0:
span = sentry_sdk.start_span(description="Eat Slice")
span = sentry_sdk.start_span(name="Eat Slice")
eat_slice(pizza.slices.pop())
span.finish()
```
<Alert title="Changed in 2.15.0" level="info">

The parameter `name` in `start_span()` used to be called `description`. In version 2.15.0 `description` was deprecated and from 2.15.0 on, only `name` should be used. `description` will be removed in `3.0.0`.

</Alert>


When you create your span manually, make sure to call `span.finish()` after the block of code you want to wrap in a span to finish the span. If you do not finish the span it will not be sent to Sentry.

Expand All @@ -108,11 +120,18 @@ def chew():
...

def eat_slice(slice):
with sentry_sdk.start_span(description="Eat Slice"):
with sentry_sdk.start_span(description="Chew"):
with sentry_sdk.start_span(name="Eat Slice"):
with sentry_sdk.start_span(name="Chew"):
chew()
```

<Alert title="Changed in 2.15.0" level="info">

The parameter `name` in `start_span()` used to be called `description`. In version 2.15.0 `description` was deprecated and from 2.15.0 on, only `name` should be used. `description` will be removed in `3.0.0`.

</Alert>


### Using a Decorator

```python
Expand All @@ -136,15 +155,21 @@ def chew():
...

def eat_slice(slice):
parent_span = sentry_sdk.start_span(description="Eat Slice")
parent_span = sentry_sdk.start_span(name="Eat Slice")

child_span = parent_span.start_child(description="Chew")
child_span = parent_span.start_child(name="Chew")
chew()
child_span.finish()

parent_span.finish()
```

<Alert title="Changed in 2.15.0" level="info">

The parameter `name` in `start_span()` used to be called `description`. In version 2.15.0 `description` was deprecated and from 2.15.0 on, only `name` should be used. `description` will be removed in `3.0.0`.

</Alert>

The parameters of `start_span()` and `start_child()` are the same. See the [API reference](https://getsentry.github.io/sentry-python/api.html#sentry_sdk.api.start_span) for more details.

When you create your span manually, make sure to call `span.finish()` after the block of code you want to wrap in a span to finish the span. If you do not finish the span it will not be sent to Sentry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ with sentry_sdk.start_transaction(
# Create the span
with sentry_sdk.start_span(
op="queue.publish",
description="queue_producer",
name="queue_producer",
) as span:
# Set span data
span.set_data("messaging.message.id", message_id)
Expand Down Expand Up @@ -118,7 +118,7 @@ with sentry_sdk.start_transaction(transaction):
# Create the span
with sentry_sdk.start_span(
op="queue.process",
description="queue_consumer",
name="queue_consumer",
) as span:
# Set span data
span.set_data("messaging.message.id", message["message_id"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import requests
def make_request(method, url):
span = sentry_sdk.start_span(
op="http.client",
description="%s %s" % (method, url),
name="%s %s" % (method, url),
)

span.set_data("http.request.method", method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ from sentry_sdk.ai.monitoring import ai_track, record_token_usage
import sentry_sdk
import requests

@ai_track(description="AI tool")
@ai_track("AI tool")
def some_workload_function(**kwargs):
"""
This function is an example of calling arbitrary code with @ai_track so that it shows up in the Sentry trace
"""
time.sleep(5)

@ai_track(description="LLM")
@ai_track("LLM")
def some_llm_call():
"""
This function is an example of calling an LLM provider that isn't officially supported by Sentry.
"""
with sentry_sdk.start_span(op="ai.chat_completions.create.examplecom", description="Example.com LLM") as span:
with sentry_sdk.start_span(op="ai.chat_completions.create.examplecom", name="Example.com LLM") as span:
result = requests.get('https://example.com/api/llm-chat?question=say+hello').json()
# this annotates the tokens used by the LLM so that they show up in the graphs in the dashboard
record_token_usage(span, total_tokens=result["usage"]["total_tokens"])
return result["text"]

@ai_track(description="My AI pipeline")
@ai_track("My AI pipeline")
def some_pipeline():
"""
The topmost level function with @ai_track gets the operation "ai.pipeline", which makes it show up
Expand Down
2 changes: 1 addition & 1 deletion platform-includes/performance/add-spans-example/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sentry_sdk

def process_item(item):
# omitted code...
with sentry_sdk.start_span(op="http", description="GET /") as span:
with sentry_sdk.start_span(op="http", name="GET /") as span:
response = my_custom_http_library.request("GET", "/")
span.set_tag("http.status_code", response.status_code)
span.set_data("http.foobarsessionid", get_foobar_sessionid())
Expand Down
Loading