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 2 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 @@ -51,7 +51,7 @@ 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())

```
Expand Down Expand Up @@ -94,10 +94,10 @@ def swallow():
...

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()
with sentry_sdk.start_span(description="Swallow"):
with sentry_sdk.start_span(name="Swallow"):
swallow()

```
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