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

Public API for getting metrics that have been set #38

Open
springmeyer opened this issue Mar 24, 2020 · 3 comments
Open

Public API for getting metrics that have been set #38

springmeyer opened this issue Mar 24, 2020 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@springmeyer
Copy link

I have a usecase where I want to get access to one or all the metrics that have been set with putMetric before sending a response back to the user. Specifically I'm planning on putting some of the metric values into server timing headers so that I can tie clientside behavior back to serverside metrics.

I'm found that while there is not a public getMetric method I can get access to previously set metrics by inspecting the data here

My question is whether this is an okay, somewhat stable method to use? Or if this is exclusively private/internal data that I should not be touching? If the latter, is there interest in adding formal getMetric or getProperty methods?

@jaredcnance
Copy link
Member

jaredcnance commented Mar 24, 2020

Any non-public members are subject to changes without changing major versions so while I don’t have any plans to change them, I wouldn’t recommend depending on internal/private members because you can’t rely on semver to identify breaking changes.

Would access to the current metrics context suffice? Seems this would be the only blocker.

private context: MetricsContext;

@springmeyer
Copy link
Author

Thanks for the thoughts!

Would access to the current metrics context suffice? Seems this would be the only blocker.

Yes, that is working right now. I'm currently getting access like:

context.metrics.forEach( (value, key) => {
      console.log(value,key);
    })

which dumps metrics I've added (in earlier code) like:

MetricValues { values: [ 1 ], unit: 'None' } 'RequestCount'
MetricValues { values: [ 314.675 ], unit: 'Milliseconds' } 'ResponseTime'

So, if that seems reasonable to you and unlikely to break, I'm 👍 on doing this. But I figured I'd ask before assuming.

@jaredcnance
Copy link
Member

jaredcnance commented Mar 25, 2020

The metrics are public on the context, so that is a safe bet. I think we just need to add public access to the context on the logger and export MetricsContext: https://github.com/awslabs/aws-embedded-metrics-node/blob/master/src/index.ts

@jaredcnance jaredcnance added enhancement New feature or request good first issue Good for newcomers not started labels Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants