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

feat(instrumentation-grpc): set net.peer.name and net.peer.port on client spans #3430

Conversation

ty-elastic
Copy link
Contributor

@ty-elastic ty-elastic commented Nov 20, 2022

Which problem is this PR solving?

Set net.peer.name and net.peer.port span attribute on gRPC client spans as a hint to APMs to look for service dependencies. This is a requirement of OTEL gRPC span conventions.

Fixes #3429

Short description of the changes

  • decode grpc destination URI (typically dns:host:port)
  • set as net.peer.name and net.peer.port

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • verified net.peer.name and net.peer.port exists as a span attribute in grpc client spans using otel collector
  • passes unit tests

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added

@ty-elastic ty-elastic requested a review from a team as a code owner November 20, 2022 15:53
Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

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

could you add a test for this ?

@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch from 23aedb3 to 2e48472 Compare November 20, 2022 20:54
@ty-elastic
Copy link
Contributor Author

@vmarchaud, absolutely! unit tests added.

@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch from 2e48472 to 0880262 Compare November 20, 2022 23:15
@codecov
Copy link

codecov bot commented Nov 21, 2022

Codecov Report

Merging #3430 (dd37c6e) into main (285f282) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3430      +/-   ##
==========================================
+ Coverage   93.75%   93.77%   +0.02%     
==========================================
  Files         248      248              
  Lines        7552     7561       +9     
  Branches     1576     1578       +2     
==========================================
+ Hits         7080     7090      +10     
+ Misses        472      471       -1     
Impacted Files Coverage Δ
...elemetry-instrumentation-grpc/src/grpc-js/index.ts 92.30% <100.00%> (+0.27%) ⬆️
...entelemetry-instrumentation-grpc/src/grpc/index.ts 93.98% <100.00%> (+0.18%) ⬆️
...es/opentelemetry-instrumentation-grpc/src/utils.ts 94.23% <100.00%> (+0.11%) ⬆️
...-trace-base/src/platform/node/RandomIdGenerator.ts 93.75% <0.00%> (+6.25%) ⬆️

@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch 2 times, most recently from 4d65da9 to d341bbe Compare November 21, 2022 12:29
@ty-elastic
Copy link
Contributor Author

added CHANGELOG addition, fixed lint error

@@ -306,6 +306,11 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
[SemanticAttributes.RPC_METHOD]: method,
[SemanticAttributes.RPC_SERVICE]: service,
});
// set peer.service from target (e.g., "dns:otel-productcatalogservice:8080") as a hint to APMs
const parsedUri = URI_REGEX.exec(this.getChannel().getTarget());
Copy link
Member

Choose a reason for hiding this comment

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

The specification defines that peer.service:

SHOULD be equal to the actual service.name resource attribute of the remote service if any.

Channel#getTarget returns the address that this client is connected to, rather than the desired service.name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha - I agree! I was looking at values in flight from some service which happen to set it to host:port. I'll adjust. Thank you for the reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lemme see how other auto-instrumentation frameworks set this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@legendecas - ok, I've change this to set net.peer.name and net.peer.port per OTEL RPC conventions.

Per this, we always set net.peer.name regardless of whether is a DNS name or IP: "Sometimes host name is only available to instrumentation as a string which may contain DNS name or IP address. net.peer.name SHOULD be set to the available known hostname (e.g., "127.0.0.1" if connecting to an URL https://127.0.0.1.com/foo)."

@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch from d341bbe to 067caa9 Compare November 30, 2022 20:46
@ty-elastic ty-elastic changed the title feat(instrumentation-grpc): set peer.service on client spans feat(instrumentation-grpc): set net.peer.name and net.peer.port on client spans Nov 30, 2022
@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch from 067caa9 to 6f46a77 Compare November 30, 2022 21:27
@vmarchaud
Copy link
Member

@ty-elastic Could you rebase and fix conflicts please ?

@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch 2 times, most recently from fcaee74 to f076625 Compare December 2, 2022 15:29
@ty-elastic
Copy link
Contributor Author

@vmarchaud, rebased, conflicts resolved. thx!

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

To fix the linter complaints, you can run npm run lint:fix in experimental/packages/opentelemetry-instrumentation-grpc.

@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch from f076625 to 592b13a Compare December 5, 2022 17:51
@ty-elastic ty-elastic force-pushed the ty-elastic/instrumentation-grpc-peerservice branch from 592b13a to dd37c6e Compare December 5, 2022 17:52
@ty-elastic
Copy link
Contributor Author

@legendecas , my pleasure! linted... thanks!

@vmarchaud vmarchaud merged commit 6ea4b41 into open-telemetry:main Dec 5, 2022
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.

Set net.peer.name and net.peer.port on grpc client spans
3 participants