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

fix(grpc): Allow gRPC connections via Unix socket #1833

Merged
merged 8 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1679](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1679))
- `opentelemetry-instrumentation-asgi` Add `http.server.response.size` metric
([#1789](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1789))
- `opentelemetry-instrumentation-grpc` Allow gRPC connections via Unix socket
([#1833](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1833))

## Version 1.18.0/0.39b0 (2023-05-10)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,30 @@ def _start_span(
# * ipv4:127.0.0.1:57284
# * ipv4:10.2.1.1:57284,127.0.0.1:57284
#
try:
ip, port = (
context.peer().split(",")[0].split(":", 1)[1].rsplit(":", 1)
)
ip = unquote(ip)
attributes.update(
{
SpanAttributes.NET_PEER_IP: ip,
SpanAttributes.NET_PEER_PORT: port,
}
)
if context.peer() != "unix:":
try:
ip, port = (
context.peer()
.split(",")[0]
.split(":", 1)[1]
.rsplit(":", 1)
)
ip = unquote(ip)
attributes.update(
{
SpanAttributes.NET_PEER_IP: ip,
SpanAttributes.NET_PEER_PORT: port,
}
)

# other telemetry sources add this, so we will too
if ip in ("[::1]", "127.0.0.1"):
attributes[SpanAttributes.NET_PEER_NAME] = "localhost"
# other telemetry sources add this, so we will too
if ip in ("[::1]", "127.0.0.1"):
attributes[SpanAttributes.NET_PEER_NAME] = "localhost"

except IndexError:
aabmass marked this conversation as resolved.
Show resolved Hide resolved
logger.warning("Failed to parse peer address '%s'", context.peer())
except IndexError:
logger.warning(
"Failed to parse peer address '%s'", context.peer()
)

return self._tracer.start_as_current_span(
name=handler_call_details.method,
Expand Down
Loading