Skip to content

Commit 4f922a2

Browse files
committed
Merge branch 'main' into aiohttp-server-instrumentation
2 parents 82d3b8d + 32ae65e commit 4f922a2

File tree

3 files changed

+107
-121
lines changed

3 files changed

+107
-121
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
([#1679](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1679))
2626
- `opentelemetry-instrumentation-asgi` Add `http.server.response.size` metric
2727
([#1789](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1789))
28+
- `opentelemetry-instrumentation-grpc` Allow gRPC connections via Unix socket
29+
([#1833](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1833))
2830

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

instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -250,24 +250,30 @@ def _start_span(
250250
# * ipv4:127.0.0.1:57284
251251
# * ipv4:10.2.1.1:57284,127.0.0.1:57284
252252
#
253-
try:
254-
ip, port = (
255-
context.peer().split(",")[0].split(":", 1)[1].rsplit(":", 1)
256-
)
257-
ip = unquote(ip)
258-
attributes.update(
259-
{
260-
SpanAttributes.NET_PEER_IP: ip,
261-
SpanAttributes.NET_PEER_PORT: port,
262-
}
263-
)
253+
if context.peer() != "unix:":
254+
try:
255+
ip, port = (
256+
context.peer()
257+
.split(",")[0]
258+
.split(":", 1)[1]
259+
.rsplit(":", 1)
260+
)
261+
ip = unquote(ip)
262+
attributes.update(
263+
{
264+
SpanAttributes.NET_PEER_IP: ip,
265+
SpanAttributes.NET_PEER_PORT: port,
266+
}
267+
)
264268

265-
# other telemetry sources add this, so we will too
266-
if ip in ("[::1]", "127.0.0.1"):
267-
attributes[SpanAttributes.NET_PEER_NAME] = "localhost"
269+
# other telemetry sources add this, so we will too
270+
if ip in ("[::1]", "127.0.0.1"):
271+
attributes[SpanAttributes.NET_PEER_NAME] = "localhost"
268272

269-
except IndexError:
270-
logger.warning("Failed to parse peer address '%s'", context.peer())
273+
except IndexError:
274+
logger.warning(
275+
"Failed to parse peer address '%s'", context.peer()
276+
)
271277

272278
return self._tracer.start_as_current_span(
273279
name=handler_call_details.method,

0 commit comments

Comments
 (0)