Skip to content

Commit

Permalink
Remove expensive calculation of gRPC message size (#3168)
Browse files Browse the repository at this point in the history
* Remove expensive calculation of gRPC message size

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* mod tidy

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
  • Loading branch information
Aneurysm9 and dmathieu committed Jan 23, 2023
1 parent 4de1b23 commit 4afb19f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 96 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add missing recommended AWS Lambda resource attributes `faas.instance` and `faas.max_memory` in `go.opentelemetry.io/contrib/detectors/aws/lambda`. (#3148)
- Improve documentation for `samplers/jaegerremote` by providing examples of sampling endpoints. (#3147)

### Changed

- `otelgrpc`: Remove expensive calculation of uncompressed message size attribute. (#3168)

## [1.12.0/0.37.0/0.6.0]

### Added
Expand Down
20 changes: 6 additions & 14 deletions instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,16 @@ import (
type messageType attribute.KeyValue

// Event adds an event of the messageType to the span associated with the
// passed context with id and size (if message is a proto message).
func (m messageType) Event(ctx context.Context, id int, message interface{}) {
// passed context with a message id.
func (m messageType) Event(ctx context.Context, id int, _ interface{}) {
span := trace.SpanFromContext(ctx)
if !span.IsRecording() {
return
}
if p, ok := message.(proto.Message); ok {
span.AddEvent("message", trace.WithAttributes(
attribute.KeyValue(m),
RPCMessageIDKey.Int(id),
RPCMessageUncompressedSizeKey.Int(proto.Size(p)),
))
} else {
span.AddEvent("message", trace.WithAttributes(
attribute.KeyValue(m),
RPCMessageIDKey.Int(id),
))
}
span.AddEvent("message", trace.WithAttributes(
attribute.KeyValue(m),
RPCMessageIDKey.Int(id),
))
}

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
go.opentelemetry.io/otel/sdk/metric v0.34.0
go.uber.org/goleak v1.2.0
google.golang.org/grpc v1.52.0
google.golang.org/protobuf v1.28.1
)

require (
Expand All @@ -30,6 +29,7 @@ require (
golang.org/x/text v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading

0 comments on commit 4afb19f

Please sign in to comment.