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

Allow setting custom metric attributes in otelhttp transport #5876

Conversation

luca-filipponi
Copy link
Contributor

@luca-filipponi luca-filipponi commented Jul 9, 2024

There is no option to include a set of attribute on metrics for every request

Copy link

linux-foundation-easycla bot commented Jul 9, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch from 977c738 to 4570245 Compare July 9, 2024 13:08
@dmathieu
Copy link
Member

dmathieu commented Jul 9, 2024

You shouldn't need this option. The same can be achieved with a view.
https://opentelemetry.io/docs/languages/go/instrumentation/#registering-views

@luca-filipponi
Copy link
Contributor Author

luca-filipponi commented Jul 9, 2024

You shouldn't need this option. The same can be achieved with a view.

Ohh nice, so i guess this is not useful! Will check out how this works

@luca-filipponi
Copy link
Contributor Author

@dmathieu i've checked out the documentation of the view, but I don't see an option to add attributes with that

you can only filter them?
https://github.com/open-telemetry/opentelemetry-go/blob/82184aa44bb892ad95d98e09196a7c331f17797e/sdk/metric/instrument.go#L146

@dmathieu
Copy link
Member

dmathieu commented Jul 9, 2024

Urgh yes sorry, my bad.

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.5%. Comparing base (abb5953) to head (68d3c06).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #5876   +/-   ##
=====================================
  Coverage   65.5%   65.5%           
=====================================
  Files        203     203           
  Lines      12926   12936   +10     
=====================================
+ Hits        8474    8486   +12     
+ Misses      4198    4197    -1     
+ Partials     254     253    -1     
Files Coverage Δ
instrumentation/net/http/otelhttp/config.go 82.0% <100.0%> (+1.1%) ⬆️
instrumentation/net/http/otelhttp/transport.go 95.2% <100.0%> (+0.2%) ⬆️

... and 1 file with indirect coverage changes

@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch from 4570245 to 69f66d2 Compare July 9, 2024 14:44
@luca-filipponi
Copy link
Contributor Author

Created an issue: #5877, not sure if this is the best way to add this functionality (maybe there can be an option to add attributes in a the view? but it seems more invasive)

@luca-filipponi luca-filipponi marked this pull request as ready for review July 9, 2024 14:56
@luca-filipponi luca-filipponi requested a review from a team July 9, 2024 14:56
@dmathieu dmathieu changed the title added option on http transport for having default attributes to be i… Allow setting custom metric attributes in otelhttp transport Jul 10, 2024
Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

Typically, with this kind of attributes in otelhttp and other instrumentations, the follow request we have seen is to be able to set data dynamically, depending on the request data.

I wonder if it would be worth going directly with a callback that accepts the request as a parameter?

CHANGELOG.md Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/config.go Outdated Show resolved Hide resolved
@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch 2 times, most recently from 02ba617 to 21fbc0f Compare July 10, 2024 08:01
@luca-filipponi
Copy link
Contributor Author

I wonder if it would be worth going directly with a callback that accepts the request as a parameter?

yea, pretty sure I can do that 😄 will send changes in a bit

@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch from 0551a23 to 4e2fa69 Compare July 10, 2024 12:18
instrumentation/net/http/otelhttp/transport.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/transport.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/transport.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/transport.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/transport.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/transport.go Outdated Show resolved Hide resolved
@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch 2 times, most recently from d730e7a to 0f4aa08 Compare July 12, 2024 09:26
@luca-filipponi
Copy link
Contributor Author

@dmathieu what is the process for merging? do you want me to squash commits? is there anything else that i should do?

@dmathieu
Copy link
Member

A second approval from a member of @open-telemetry/go-approvers is required before we can merge.

@dashpole
Copy link
Contributor

I think this has been discussed, but I don't remember the outcome. Can you update the description to include it?

Why can't the Labeler be used to accomplish this?

@dmathieu
Copy link
Member

It's mentioned in #5877.

@dashpole
Copy link
Contributor

Thanks. Does it need to be a function, then, if the goal is to add constant labels not based on the request? This seems to just duplicate the Labeler's functionality right now.

@dmathieu
Copy link
Member

I asked for it to be a function here, as every other option we've set like this before was always followed with a request to be able to dynamically add data rather than statically.
I don't mind reverting that if you feel against it though.

@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch 6 times, most recently from dc2b367 to 77af1b0 Compare August 9, 2024 15:35
@luca-filipponi
Copy link
Contributor Author

@hanyuancheung @dmathieu i've squashed all the commits and rebased with main. Let me know if you need me to do something else.

CHANGELOG.md Outdated Show resolved Hide resolved
@luca-filipponi luca-filipponi force-pushed the feature/default_attribute_http_transport branch from 77af1b0 to 90b1f5d Compare August 20, 2024 17:50
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Damien Mathieu <42@dmathieu.com>
@dmathieu dmathieu merged commit 9b2f4d9 into open-telemetry:main Aug 21, 2024
33 checks passed
@MrAlias MrAlias added this to the v1.29.0 milestone Aug 22, 2024
MrAlias added a commit that referenced this pull request Aug 23, 2024
This release is the last to support [Go 1.21]. The next release will
require at least [Go 1.22].

### Added

- Add the `WithSpanAttributes` and `WithMetricAttributes` methods to set
custom attributes to the stats handler in
`go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`.
(#5133)
- The `go.opentelemetry.io/contrib/bridges/otelzap` module. This module
provides an OpenTelemetry logging bridge for `go.uber.org/zap`. (#5191)
- Support for the `OTEL_HTTP_CLIENT_COMPATIBILITY_MODE=http/dup`
environment variable in
`go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` to emit
attributes for both the v1.20.0 and v1.26.0 semantic conventions.
(#5401)
- The `go.opentelemetry.io/contrib/bridges/otelzerolog` module. This
module provides an OpenTelemetry logging bridge for
`github.com/rs/zerolog`. (#5405)
- Add `WithGinFilter` filter parameter in
`go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`
to allow filtering requests with `*gin.Context`. (#5743)
- Support for stdoutlog exporter in
`go.opentelemetry.io/contrib/config`. (#5850)
- Add macOS ARM64 platform to the compatibility testing suite. (#5868)
- Add new runtime metrics to
`go.opentelemetry.io/contrib/instrumentation/runtime`, which are still
disabled by default. (#5870)
- Add the `WithMetricsAttributesFn` option to allow setting dynamic,
per-request metric attributes in
`go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#5876)
- The `go.opentelemetry.io/contrib/config` package supports configuring
`with_resource_constant_labels` for the prometheus exporter. (#5890)
- Support [Go 1.23]. (#6017)

### Removed

- The deprecated `go.opentelemetry.io/contrib/processors/baggagecopy`
package is removed. (#5853)

### Fixed

- Race condition when reading the HTTP body and writing the response in
`go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#5916)

[Go 1.23]: https://go.dev/doc/go1.23
[Go 1.22]: https://go.dev/doc/go1.22
[Go 1.21]: https://go.dev/doc/go1.21
dhowden added a commit to dhowden/opentelemetry-go-contrib that referenced this pull request Sep 5, 2024
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