question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not at all clear how to add labels to the Summary(...) time() decorator pattern

See original GitHub issue

In the README, in one of the samples, we have:

# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')

# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):

But what if I want to add labels to this? I can’t figure out how to make it work. My current code which doesn’t work is:

TRADE_REQUEST_TIME = Summary(
    'request_processing_seconds',
    'Time spent processing a request',
    labelnames=('method', 'endpoint', 'whitelabel'),
    labelvalues=('get', '/trade/', settings.WHITELABEL_NAME))


@TRADE_REQUEST_TIME.time()
def render_trade_page(request, sport):
    ...

But I get:

    @TRADE_REQUEST_TIME.time()
AttributeError: '_LabelWrapper' object has no attribute 'time'

Any advice?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
kamalmarhubicommented, Oct 18, 2016

Unfortunately that’s not valid syntax. However, this works:

REQUEST_TIME = Summary(
    'request_processing_seconds',
    'Time spent processing a request',
   ('method', 'endpoint', 'whitelabel')
)

TRADE_REQUEST_TIME = REQUEST_TIME.labels('GET', '/trade/', settings.WHITELABEL_NAME)

@TRADE_REQUEST_TIME.time()
def render_trade_page(request, sport):
  ...

It’s probably worth pushing this down further into your serving code, so you don’t need to have the noise of all the submetric definitions.

2reactions
brian-brazilcommented, Nov 3, 2016

Yes, that’s my up. The top is where the calls enter the system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Metric types - Prometheus.io
Alerting based on metrics. Metric types. Counter; Gauge; Histogram; Summary. The Prometheus client libraries offer four core metric types. These are currently ...
Read more >
Intro to Labeling Functions - Snorkel.org
Writing Labeling Functions: We write Python programs that take as input a data point and assign labels (or abstain) using heuristics, pattern matching,...
Read more >
The Details disclosure element - HTML - MDN Web Docs
The contents of the <summary> element are used as the label for the disclosure widget. Try it. HTML Demo: <details>. Reset. HTML CSS...
Read more >
Organize resources using labels | Compute Engine ...
Add or update labels to existing resources. You can add labels or update existing labels on resources by using the Google Cloud console,...
Read more >
Icon Usability - Nielsen Norman Group
If that object, action, or idea is not immediately clear to users, the icon is ... Icon labels should be visible at all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found