Skip to content

Commit aed659b

Browse files
Update docstring
1 parent b338833 commit aed659b

File tree

5 files changed

+41
-15
lines changed
  • instrumentation
    • opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi
    • opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django
    • opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon
    • opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask
    • opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi

5 files changed

+41
-15
lines changed

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,12 @@ def client_response_hook(span: Span, scope: Scope, message: dict[str, Any]):
206206
207207
Custom Metrics Attributes using Labeler
208208
***************************************
209-
The ASGI instrumentation reads from a Labeler utility that supports adding custom attributes
210-
to the HTTP duration metrics recorded by the instrumentation.
209+
The ASGI instrumentation reads from a labeler utility that supports adding custom
210+
attributes to HTTP duration metrics at record time. The custom attributes are
211+
stored only within the context of an instrumented request or operation. The
212+
instrumentor does not overwrite base attributes that exist at the same keys as
213+
any custom attributes.
214+
211215
212216
.. code-block:: python
213217
@@ -220,18 +224,21 @@ def client_response_hook(span: Span, scope: Scope, message: dict[str, Any]):
220224
app = Quart(__name__)
221225
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)
222226
223-
@app.route("/user/<user_id>")
227+
@app.route("/users/<user_id>/")
224228
async def user_profile(user_id):
225229
# Get the labeler for the current request
226230
labeler = get_labeler()
231+
227232
# Add custom attributes to ASGI instrumentation metrics
228233
labeler.add("user_id", user_id)
229234
labeler.add("user_type", "registered")
235+
230236
# Or, add multiple attributes at once
231237
labeler.add_attributes({
232238
"feature_flag": "new_ui",
233239
"experiment_group": "control"
234240
})
241+
235242
return f"User profile for {user_id}"
236243
237244
if __name__ == "__main__":

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ def response_hook(span, request, response):
235235
236236
Custom Metrics Attributes using Labeler
237237
***************************************
238-
The Django instrumentation reads from a Labeler utility that supports adding custom attributes to the HTTP duration metrics recorded by the instrumentation.
238+
The Django instrumentation reads from a labeler utility that supports adding custom
239+
attributes to HTTP duration metrics at record time. The custom attributes are
240+
stored only within the context of an instrumented request or operation. The
241+
instrumentor does not overwrite base attributes that exist at the same keys as
242+
any custom attributes.
243+
239244
240245
.. code:: python
241246
@@ -245,7 +250,7 @@ def response_hook(span, request, response):
245250
246251
DjangoInstrumentor().instrument()
247252
248-
# For urlpattern `/user/<user_id>/` mapped elsewhere
253+
# Note: urlpattern `/users/<user_id>/` mapped elsewhere
249254
def my_user_view(request, user_id):
250255
# Get the labeler for the current request
251256
labeler = get_labeler()

instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,35 +182,41 @@ def response_hook(span, req, resp):
182182
183183
Custom Metrics Attributes using Labeler
184184
***************************************
185-
The Falcon instrumentation reads from a Labeler utility that supports adding custom attributes
186-
to the HTTP duration metrics recorded by the instrumentation.
185+
The Falcon instrumentation reads from a labeler utility that supports adding custom
186+
attributes to HTTP duration metrics at record time. The custom attributes are
187+
stored only within the context of an instrumented request or operation. The
188+
instrumentor does not overwrite base attributes that exist at the same keys as
189+
any custom attributes.
187190
188191
189192
.. code-block:: python
190193
191194
import falcon
195+
192196
from opentelemetry.instrumentation._labeler import get_labeler
193197
from opentelemetry.instrumentation.falcon import FalconInstrumentor
194198
195199
FalconInstrumentor().instrument()
196-
197200
app = falcon.App()
198201
199202
class UserProfileResource:
200203
def on_get(self, req, resp, user_id):
201204
# Get the labeler for the current request
202205
labeler = get_labeler()
206+
203207
# Add custom attributes to Falcon instrumentation metrics
204208
labeler.add("user_id", user_id)
205209
labeler.add("user_type", "registered")
210+
206211
# Or, add multiple attributes at once
207212
labeler.add_attributes({
208213
"feature_flag": "new_ui",
209214
"experiment_group": "control"
210215
})
216+
211217
resp.text = f'User profile for {user_id}'
212218
213-
app.add_route('/user/{user_id}', UserProfileResource())
219+
app.add_route('/users/{user_id}/', UserProfileResource())
214220
215221
API
216222
---

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,24 @@ def hello():
9797
9898
Custom Metrics Attributes using Labeler
9999
***************************************
100-
The Flask instrumentation reads from a Labeler utility that supports adding custom attributes
101-
to the HTTP request duration metrics recorded by the instrumentation.
100+
The Flask instrumentation reads from a labeler utility that supports adding custom
101+
attributes to HTTP duration metrics at record time. The custom attributes are
102+
stored only within the context of an instrumented request or operation. The
103+
instrumentor does not overwrite base attributes that exist at the same keys as
104+
any custom attributes.
105+
102106
103107
.. code-block:: python
104108
105109
from flask import Flask
106-
from opentelemetry.instrumentation.flask import FlaskInstrumentor
110+
107111
from opentelemetry.instrumentation._labeler import get_labeler
112+
from opentelemetry.instrumentation.flask import FlaskInstrumentor
108113
109114
app = Flask(__name__)
110115
FlaskInstrumentor().instrument_app(app)
111116
112-
@app.route("/user/<user_id>")
117+
@app.route("/users/<user_id>/")
113118
def user_profile(user_id):
114119
# Get the labeler for the current request
115120
labeler = get_labeler()

instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ def GET(self):
8181
8282
Custom Metrics Attributes using Labeler
8383
***************************************
84-
The WSGI instrumentation reads from a labeler utility that supports adding custom attributes
85-
to HTTP duration metrics at record time.
84+
The WSGI instrumentation reads from a labeler utility that supports adding custom
85+
attributes to HTTP duration metrics at record time. The custom attributes are
86+
stored only within the context of an instrumented request or operation. The
87+
instrumentor does not overwrite base attributes that exist at the same keys as
88+
any custom attributes.
8689
8790
.. code-block:: python
8891

0 commit comments

Comments
 (0)