Skip to content

Commit 7dfbc92

Browse files
committed
fix spectator-py example
The location was set to `none`, which disables publishing metrics. This can be confusing for new users who copy-paste the example.
1 parent 38b6102 commit 7dfbc92

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

docs/spectator/lang/py/usage.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ pip install netflix-spectator-py
2020

2121
## Instrumenting Code
2222

23+
### Simple Example
24+
25+
```python
26+
import logging
27+
28+
from flask import Flask, request, Response
29+
from flask.logging import default_handler
30+
from spectator.registry import Registry
31+
32+
root_logger = logging.getLogger()
33+
root_logger.setLevel(logging.DEBUG)
34+
root_logger.addHandler(default_handler)
35+
36+
registry = Registry()
37+
38+
app = Flask(__name__)
39+
40+
@app.route("/")
41+
def root():
42+
return Response("Usage: /api/v1/play?country=foo&title=bar")
43+
44+
@app.route("/api/v1/play", methods=["GET", "POST"])
45+
def play():
46+
country = request.args.get("country", default="none")
47+
title = request.args.get("title", default="none")
48+
registry.counter("server.requestCount", {"version": "v1"}).increment()
49+
return Response(f"requested play for country={country} title={title}")
50+
```
51+
52+
Save this snippet as `app.py`, then `flask --app app run`.
53+
54+
### Complex Example
55+
2356
```python
2457
import logging
2558

@@ -33,7 +66,7 @@ root_logger = logging.getLogger()
3366
root_logger.setLevel(logging.DEBUG)
3467
root_logger.addHandler(default_handler)
3568

36-
config = Config(location="none", extra_common_tags={"nf.platform": "my_platform"})
69+
config = Config(extra_common_tags={"nf.platform": "my_platform"})
3770
registry = Registry(config)
3871

3972
request_count_id = registry.new_id("server.requestCount", {"version": "v1"})
@@ -42,12 +75,10 @@ response_size = registry.distribution_summary("server.responseSize")
4275

4376
app = Flask(__name__)
4477

45-
4678
@app.route("/")
4779
def root():
4880
return Response("Usage: /api/v1/play?country=foo&title=bar")
4981

50-
5182
@app.route("/api/v1/play", methods=["GET", "POST"])
5283
def play():
5384
if request.method == "GET":

0 commit comments

Comments
 (0)