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

Update otelfiber metrics implementation #409

Merged
merged 7 commits into from
Jan 16, 2023

Conversation

onematchfox
Copy link
Contributor

@onematchfox onematchfox commented Dec 20, 2022

Whilst trying out the metrics implementation added in #385 I noticed that all metrics were being reported on the route /. This is because the route was being accessed prior to c.Next() being called. As per the docs (and the existing tracing implementation) this can be only be set later in the method.

Do not rely on c.Route() in middlewares before calling c.Next() - c.Route() returns the last executed route.

So, first and foremost, this PR sets out to resolve that issue. In doing so I decided to use the opportunity to add the status code attribute as per the recommendations and, to prevent issues in future, expanded the tests to assert that the metrics are being produced as expected.

On a related note, I noticed that:

  • this module currently makes use of v1.4.0 of the semconv package (here and here). Given that it is referencing the latest versions of the main libraries I wonder if this shouldn't also be updated to the latest version (v1.12.0) as well?
  • related to the above, the attributes added this module (given it's inspiration on the semconv module) don't actually conform with the semantic conventions spec for either metrics and or traces. E.g. the use of http.server_name over net.host.name

FWIW, I did initially consider bundling changes to the attribute names to comply with the latest spec into this PR but figured those changes probably deserved a separate PR as I'm sure there is some discussion to be had.

@gaby
Copy link
Member

gaby commented Dec 21, 2022

@onematchfox Seems like tests are failing

@onematchfox
Copy link
Contributor Author

@onematchfox Seems like tests are failing

Ooops... My bad! Should all be working now.

@gaby
Copy link
Member

gaby commented Dec 30, 2022

@onematchfox Can you bump the semconv version too? I ran into this issue about metrics being reported on / a couple days a go. So this PR should help with that.

@gaby gaby requested review from efectn and ReneWerner87 December 30, 2022 14:00
Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

Looks good, the only thing would be bumping the semconv version to .12

@onematchfox
Copy link
Contributor Author

Looks good, the only thing would be bumping the semconv version to .12

Bumped version as requested. I have however left the metric attributes as is for now. Do you also want to tackle aligning these with the latest version of the spec as well in this PR?

For reference see
HTTP Metrics - https://opentelemetry.io/docs/reference/specification/metrics/semantic_conventions/http-metrics/
HTTP Spans - https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/

@onematchfox onematchfox requested review from gaby and removed request for ReneWerner87 and efectn December 31, 2022 14:15
@gaby
Copy link
Member

gaby commented Dec 31, 2022

@onematchfox Given that we are using the latest opentelemetry, makes sense to also update the metrics attributes in this PR.

@onematchfox onematchfox force-pushed the metrics branch 2 times, most recently from fb27ab5 to 52bff88 Compare January 2, 2023 12:00
…12.0`

Includes:
- making `http.server_name` optional - this attribute is only ever mentioned as an example in the "[Observability Primer](https://opentelemetry.io/docs/concepts/observability-primer/)" (see https://opentelemetry.io/search/?q=http.server_name) and seems to have been replaced-by usage of `net.host.name` instead.
- replacing `http.host` with `net.host.name`
- improved accuracy of `http.scheme` through use of `ctx.Protocol()` instead of `ctx.Context().IsTLS()`
- improved accuracy of `http.flavor`
- addition of optional attribute `net.host.port`

See https://opentelemetry.io/docs/reference/specification/metrics/semantic_conventions/http-metrics/ for more
…2.0`

Includes:
- making `http.server_name` optional - this attribute is only ever mentioned as an example in the "[Observability Primer](https://opentelemetry.io/docs/concepts/observability-primer/)" (see https://opentelemetry.io/search/?q=http.server_name) and seems to have been replaced-by usage of `[net.host.name](https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/span-general/#nethostname)` instead.
- addition of recommended attributes `http.flavor` and `http.response_content_length`
- addition of conditionally required attribute `net.host.port`
- removed optional/unmentioned attribute `net.host.ip`; this was being incorrectly set to the client IP instead of the the host. Client IP is already available via `http.client_ip`.

See https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/ for more
@onematchfox
Copy link
Contributor Author

onematchfox commented Jan 2, 2023

@onematchfox Given that we are using the latest opentelemetry, makes sense to also update the metrics attributes in this PR.

All done now. Suspect there's a few thing we may need to discuss :). Most pertinently, I wasn't quite sure how you wanted to handle the "removal" of http.server_name. I have tried to retain the attribute for those that depend on it, however I'm not sure how everyone will feel about the change in the function signature?

@ReneWerner87
Copy link
Member

@gaby can you check again, after your approvement i will merge it

@gaby
Copy link
Member

gaby commented Jan 13, 2023

Sure, will do!

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

Looks good, we may need to bump the release version since this is a breaking change when using WithServerName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants