Skip to content

feat: add status label#624

Closed
naseemkullah wants to merge 1 commit into
open-telemetry:masterfrom
naseemkullah:expand-metrics-example
Closed

feat: add status label#624
naseemkullah wants to merge 1 commit into
open-telemetry:masterfrom
naseemkullah:expand-metrics-example

Conversation

@naseemkullah

@naseemkullah naseemkullah commented Dec 15, 2019

Copy link
Copy Markdown
Member

Which problem is this PR solving?

To help users getting started to have a status label for requests when using metrics. This is a very useful label to have when counting requests as to calculate error ratios.

ref.: https://landing.google.com/sre/workbook/chapters/alerting-on-slos/

Short description of the changes

  • Added a status label that comes from res.statusCode to all counted requests

@codecov-io

codecov-io commented Dec 15, 2019

Copy link
Copy Markdown

Codecov Report

Merging #624 into master will decrease coverage by 0.08%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #624      +/-   ##
==========================================
- Coverage   92.31%   92.22%   -0.09%     
==========================================
  Files         177      183       +6     
  Lines        8728     9118     +390     
  Branches      758      798      +40     
==========================================
+ Hits         8057     8409     +352     
- Misses        671      709      +38
Impacted Files Coverage Δ
...kages/opentelemetry-plugin-dns/test/utils/utils.ts 33.33% <0%> (-26.67%) ⬇️
...opentelemetry-base/test/resources/resource.test.ts 100% <0%> (ø) ⬆️
...telemetry-plugin-grpc/test/utils/assertionUtils.ts 100% <0%> (ø) ⬆️
.../opentelemetry-plugin-dns/test/utils/assertSpan.ts 100% <0%> (ø) ⬆️
...try-plugin-dns/test/functionals/dns-enable.test.ts 100% <0%> (ø) ⬆️
...telemetry-scope-base/test/NoopScopeManager.test.ts 100% <0%> (ø) ⬆️
...res/opentelemetry-plugin-pg/test/assertionUtils.ts 100% <0%> (ø)
...postgres/opentelemetry-plugin-pg/test/testUtils.ts 15% <0%> (ø)
...ugin-postgres/opentelemetry-plugin-pg/src/utils.ts 96.96% <0%> (ø)
...-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts 91.37% <0%> (ø)
... and 3 more

@naseemkullah

naseemkullah commented Dec 15, 2019

Copy link
Copy Markdown
Member Author

Actually something is wrong, requests that should be 404 are counted as 200

Please do not merge.

% curl localhost:3000/badurl   
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /badurl</pre>
</body>
</html>

returns a 404 however:

% curl localhost:9464/metrics
# HELP requests Count all incoming requests
# TYPE requests counter
requests{route="/badurl",status="200"} 1

counts it as a 200

@dyladan dyladan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to modify the getting started code, make sure you add a line in the guide itself explaining why.

@naseemkullah

Copy link
Copy Markdown
Member Author

If you are going to modify the getting started code, make sure you add a line in the guide itself explaining why.

Will do! Any idea as to why every status label gets a 200 value despite of actual response status code?

@obecny

obecny commented Dec 16, 2019

Copy link
Copy Markdown
Member

Could you please add some description explaining why is this needed ?

@naseemkullah

Copy link
Copy Markdown
Member Author

Could you please add some description explaining why is this needed ?

Yes, my mistake, initial post updated now.

@dyladan

dyladan commented Dec 16, 2019

Copy link
Copy Markdown
Member

If you are going to modify the getting started code, make sure you add a line in the guide itself explaining why.

Will do! Any idea as to why every status label gets a 200 value despite of actual response status code?

Yes. The issue is that this middleware is too early in the process and the response code has not been set yet. The default is 200.

@naseemkullah

Copy link
Copy Markdown
Member Author

If you are going to modify the getting started code, make sure you add a line in the guide itself explaining why.

Will do! Any idea as to why every status label gets a 200 value despite of actual response status code?

Yes. The issue is that this middleware is too early in the process and the response code has not been set yet. The default is 200.

Hmm I was suspecting something of the sort, thanks for confirming. Is there an easy approach to get the actual response code?

@dyladan

dyladan commented Dec 16, 2019

Copy link
Copy Markdown
Member

If you are going to modify the getting started code, make sure you add a line in the guide itself explaining why.

Will do! Any idea as to why every status label gets a 200 value despite of actual response status code?

Yes. The issue is that this middleware is too early in the process and the response code has not been set yet. The default is 200.

Hmm I was suspecting something of the sort, thanks for confirming. Is there an easy approach to get the actual response code?

Not really an "easy" approach. morgan logging library achieves this by monkey patching the res.writeHead method which is called when the response starts to send. Not really "getting started" level though.

@naseemkullah

Copy link
Copy Markdown
Member Author

Ah shucks, ok then. Thanks!

@naseemkullah
naseemkullah deleted the expand-metrics-example branch December 16, 2019 15:04
@dyladan

dyladan commented Dec 16, 2019

Copy link
Copy Markdown
Member

Maybe you could use the on-response npm package which papers over the complexity of monkey patching writeHead.

@naseemkullah

Copy link
Copy Markdown
Member Author

I'll look into that as being able to count the # of errored requests will probably be something most users want.

MikeGoldsmith added a commit to honeycombio/opentelemetry-js that referenced this pull request Jun 3, 2026
Add getIdGeneratorFromConfiguration helper in sdk-node that maps
the config model's tracer_provider.id_generator to an SDK IdGenerator
instance. Currently only `random` is supported per the spec; unknown
types warn and fall back to the SDK default (RandomIdGenerator).

Export IdGenerator as IdGeneratorConfigModel from the configuration
package so downstream consumers can reference the type.

Based on mike/bump-config-schema-prometheus-rename which bumps the
schema to a SHA on main that includes IdGenerator (open-telemetry#624 upstream).

Closes open-telemetry#6616

Assisted-by: Claude Opus 4.6
MikeGoldsmith added a commit to honeycombio/opentelemetry-js that referenced this pull request Jun 5, 2026
Add getIdGeneratorFromConfiguration helper in sdk-node that maps
the config model's tracer_provider.id_generator to an SDK IdGenerator
instance. Currently only `random` is supported per the spec; unknown
types warn and fall back to the SDK default (RandomIdGenerator).

Export IdGenerator as IdGeneratorConfigModel from the configuration
package so downstream consumers can reference the type.

Based on mike/bump-config-schema-prometheus-rename which bumps the
schema to a SHA on main that includes IdGenerator (open-telemetry#624 upstream).

Closes open-telemetry#6616

Assisted-by: Claude Opus 4.6
MikeGoldsmith added a commit to honeycombio/opentelemetry-js that referenced this pull request Jun 8, 2026
Add getIdGeneratorFromConfiguration helper in sdk-node that maps
the config model's tracer_provider.id_generator to an SDK IdGenerator
instance. Currently only `random` is supported per the spec; unknown
types warn and fall back to the SDK default (RandomIdGenerator).

Export IdGenerator as IdGeneratorConfigModel from the configuration
package so downstream consumers can reference the type.

Based on mike/bump-config-schema-prometheus-rename which bumps the
schema to a SHA on main that includes IdGenerator (open-telemetry#624 upstream).

Closes open-telemetry#6616

Assisted-by: Claude Opus 4.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants