Skip to content

Commit 48f460a

Browse files
committed
Create a span only for the choice
1 parent c680afe commit 48f460a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

docs/manual-instrumentation.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ app = Flask(__name__)
122122
@app.route("/hello")
123123
def hello():
124124
choices = ["there", "world", "folks", "hello"]
125+
# create a span for the choice of the name, this may be a costly call in your real world application
125126
with tracer.start_as_current_span("choice") as span:
126-
choice = random.choice(choices)
127-
span.set_attribute("choice.value", choice)
128-
return f"Hello {choice}!"
127+
choice = random.choice(choices)
128+
span.set_attribute("choice.value", choice)
129+
return f"Hello {choice}!"
129130
```
130131
131132
And then we can run this application with the following command:
@@ -156,11 +157,12 @@ app = Flask(__name__)
156157
@app.route("/hello")
157158
def hello():
158159
choices = ["there", "world", "folks", "hello"]
160+
# create a span for the choice of the name, this may be a costly call in your real world application
159161
with tracer.start_as_current_span("choice") as span:
160-
choice = random.choice(choices)
161-
span.set_attribute("choice.value", choice)
162-
hello_counter.add(1, {"choice.value": choice})
163-
return f"Hello {choice}!"
162+
choice = random.choice(choices)
163+
span.set_attribute("choice.value", choice)
164+
hello_counter.add(1, {"choice.value": choice})
165+
return f"Hello {choice}!"
164166
```
165167

166168
<!-- ✅ What success looks like -->

0 commit comments

Comments
 (0)