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

otelgrpc: Add peer attributes to spans recorded by stats handlers #4539

Closed
wants to merge 6 commits into from

Conversation

pellared
Copy link
Member

@pellared pellared commented Nov 9, 2023

Fixes #4531

@pellared
Copy link
Member Author

pellared commented Nov 9, 2023

@fatsheep9146 PTAL if this implementation makes sense.

Copy link

codecov bot commented Nov 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f8f8249) 81.1% compared to head (b52c70a) 81.1%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #4539     +/-   ##
=======================================
- Coverage   81.1%   81.1%   -0.1%     
=======================================
  Files        150     150             
  Lines      10759   10757      -2     
=======================================
- Hits        8731    8729      -2     
  Misses      1872    1872             
  Partials     156     156             
Files Coverage Δ
...n/google.golang.org/grpc/otelgrpc/stats_handler.go 93.0% <100.0%> (-0.1%) ⬇️

@fatsheep9146
Copy link
Contributor

I think the total implementation makes sense to me!

@pellared pellared marked this pull request as ready for review November 9, 2023 15:53
@pellared pellared changed the title otelgrpc: Spans recorded by stats handlers add peer attributes otelgrpc: Add peer attributes to spans recorded bystats handlers Nov 9, 2023
@pellared pellared changed the title otelgrpc: Add peer attributes to spans recorded bystats handlers otelgrpc: Add peer attributes to spans recorded by stats handlers Nov 9, 2023
span := trace.SpanFromContext(ctx)
attrs := peerAttr(peerFromCtx(ctx))
span.SetAttributes(attrs...)
h.peerAttr = peerAttr(info.RemoteAddr.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

How will this work if the Handler has two connections at once?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I will carefully test it tomorrow.

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 will also double-check that the client handles concurrent calls without races.

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 also confirm that there can be a race on the client:

==================
WARNING: DATA RACE
Write at 0x00c0000a5048 by goroutine 12:
  go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.(*clientHandler).TagConn()
      /home/rpajak/repos/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go:137 +0x84

Previous read at 0x00c0000a5048 by goroutine 18:
  go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.(*clientHandler).TagRPC()
      /home/rpajak/repos/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go:119 +0x1e7

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 also found out that TagConn may be also called after TagRPC (or even not at all according to my current testing).

I think that currently it may be impossible to implement.

@pellared pellared marked this pull request as draft November 10, 2023 07:03
@pellared
Copy link
Member Author

I have currently no time to work on this. I try to go back to this in ~2weeks.

@pellared
Copy link
Member Author

I created grpc/grpc-go#6897

@pellared pellared closed this Jan 29, 2024
@pellared
Copy link
Member Author

Closed per #4873

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.

otelgrpc: Add peer attributes to spans generated by stats handlers
3 participants