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

Remove expensive calculation of gRPC message size #3168

Merged
merged 4 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `otelmux`: Add new `WithSpanNameFormatter` option to `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` to allow customizing span names. (#3041)
- Improve documentation for `samplers/jaegerremote` by providing examples of sampling endpoints. (#3147)

### Changed
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be Removed instead of changed? Or otherwise marked breaking?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be fine with moving to Removed but I don't think this counts as breaking as it relates to attributes emitted by telemetry and not package APIs.


- `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 @@ -133,15 +133,13 @@ func checkUnaryClientSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(0),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(0),
},
},
}, emptySpan.Events())
Expand All @@ -162,7 +160,6 @@ func checkUnaryClientSpans(t *testing.T, spans []trace.ReadOnlySpan) {
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
// largeReqSize from "google.golang.org/grpc/interop" + 12 (overhead).
otelgrpc.RPCMessageUncompressedSizeKey.Int(271840),
},
},
{
Expand All @@ -171,7 +168,6 @@ func checkUnaryClientSpans(t *testing.T, spans []trace.ReadOnlySpan) {
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
// largeRespSize from "google.golang.org/grpc/interop" + 8 (overhead).
otelgrpc.RPCMessageUncompressedSizeKey.Int(314167),
},
},
}, largeSpan.Events())
Expand All @@ -196,31 +192,27 @@ func checkStreamClientSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(27190),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(12),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(1834),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(45912),
},
},
// client does not record an event for the server response.
Expand All @@ -242,39 +234,34 @@ func checkStreamClientSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(21),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(31423),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(13),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(2659),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(58987),
},
},
}, streamOutput.Events())
Expand All @@ -294,63 +281,55 @@ func checkStreamClientSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(27196),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(31423),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(16),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(13),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(1839),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(2659),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(45918),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(58987),
},
},
}, pingPong.Events())
Expand All @@ -375,39 +354,34 @@ func checkStreamServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(27190),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(12),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(1834),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(45912),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(4),
},
},
}, streamInput.Events())
Expand All @@ -428,39 +402,34 @@ func checkStreamServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(21),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(31423),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(13),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(2659),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(58987),
},
},
}, streamOutput.Events())
Expand All @@ -480,63 +449,55 @@ func checkStreamServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(27196),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(31423),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(16),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(2),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(13),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(1839),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(3),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(2659),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(45918),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(4),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(58987),
},
},
}, pingPong.Events())
Expand All @@ -560,15 +521,13 @@ func checkUnaryServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(0),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
otelgrpc.RPCMessageUncompressedSizeKey.Int(0),
},
},
}, emptySpan.Events())
Expand All @@ -589,7 +548,6 @@ func checkUnaryServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("RECEIVED"),
// largeReqSize from "google.golang.org/grpc/interop" + 12 (overhead).
otelgrpc.RPCMessageUncompressedSizeKey.Int(271840),
},
},
{
Expand All @@ -598,7 +556,6 @@ func checkUnaryServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
otelgrpc.RPCMessageIDKey.Int(1),
otelgrpc.RPCMessageTypeKey.String("SENT"),
// largeRespSize from "google.golang.org/grpc/interop" + 8 (overhead).
otelgrpc.RPCMessageUncompressedSizeKey.Int(314167),
},
},
}, largeSpan.Events())
Expand Down
Loading