Skip to content

Commit

Permalink
Fix otel bridge span destination resource
Browse files Browse the repository at this point in the history
  • Loading branch information
basepi committed May 5, 2022
1 parent d2cb946 commit e81a836
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions elasticapm/contrib/opentelemetry/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ def parse_net_name(url: str):
port = http_port_from_scheme(u.scheme)
return u.netloc if not port else "{}:{}".format(u.netloc, port)

peer_port = attributes.get("net.peer.port", -1)
net_name = attributes.get("net.peer.name", attributes.get("net.peer.ip", ""))
net_port = attributes.get("net.peer.port", -1)
net_name = net_peer = attributes.get("net.peer.name", attributes.get("net.peer.ip", ""))

if net_name and (peer_port > 0):
net_name = "{}:{}".format(net_name, peer_port)
if net_name and (net_port > 0):
net_name = f"{net_name}:{net_port}"

if attributes.get("db.system"):
span_type = "db"
Expand All @@ -267,8 +267,11 @@ def parse_net_name(url: str):
elif attributes.get("http.url") or attributes.get("http.scheme"):
span_type = "external"
span_subtype = "http"
if attributes.get("http.host") and attributes.get("http.scheme"):
resource = "{}:{}".format(attributes["http.host"], attributes["http.scheme"])
http_host = attributes.get("http.host", net_peer)
if http_host:
if net_port < 0:
net_port = http_port_from_scheme(attributes.get("http.scheme"))
resource = http_host if net_port < 0 else f"{http_host}:{net_port}"
elif attributes.get("http.url"):
resource = parse_net_name(attributes["http.url"])

Expand Down

0 comments on commit e81a836

Please sign in to comment.