Skip to content

Commit

Permalink
Merge branch 'master' into add-aws-sdk-extension-performance-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex committed Dec 11, 2020
2 parents ced5b69 + 11a06db commit 0e69d10
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#237](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/237))
- Add Prometheus Remote Write Exporter integration tests in opentelemetry-docker-tests
([#216](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/216))
- `opentelemetry-instrumentation-grpc` Add tests for grpc span attributes, grpc `abort()` conditions
([#236](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/236))

### Changed
- `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-wsgi` Return `None` for `CarrierGetter` if key not found
([#1374](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/233))
- `opentelemetry-instrumentation-grpc` Comply with updated spec, rework tests
([#236](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/236))
- `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-falcon`, `opentelemetry-instrumentation-flask`, `opentelemetry-instrumentation-pyramid`, `opentelemetry-instrumentation-wsgi` Renamed `host.port` attribute to `net.host.port`
([#242](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/242))

## [0.16b1](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.16b1) - 2020-11-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def collect_request_attributes(scope):
"component": scope["type"],
"http.scheme": scope.get("scheme"),
"http.host": server_host,
"host.port": port,
"net.host.port": port,
"http.flavor": scope.get("http_version"),
"http.target": scope.get("path"),
"http.url": http_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
"component": "http",
"http.method": "GET",
"http.scheme": "http",
"host.port": 80,
"net.host.port": 80,
"http.host": "127.0.0.1",
"http.flavor": "1.0",
"http.target": "/",
Expand Down Expand Up @@ -218,7 +218,7 @@ def update_expected_server(expected):
expected[3]["attributes"].update(
{
"http.host": "0.0.0.0",
"host.port": 80,
"net.host.port": 80,
"http.url": "http://0.0.0.0/",
}
)
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_request_attributes(self):
"http.host": "127.0.0.1",
"http.target": "/",
"http.url": "http://127.0.0.1/?foo=bar",
"host.port": 80,
"net.host.port": 80,
"http.scheme": "http",
"http.server_name": "test",
"http.flavor": "1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _test_method(self, method):
"http.method": method,
"http.server_name": "falconframework.org",
"http.scheme": "http",
"host.port": 80,
"net.host.port": 80,
"http.host": "falconframework.org",
"http.target": "/",
"net.peer.ip": "127.0.0.1",
Expand All @@ -126,7 +126,7 @@ def test_404(self):
"http.method": "GET",
"http.server_name": "falconframework.org",
"http.scheme": "http",
"host.port": 80,
"net.host.port": 80,
"http.host": "falconframework.org",
"http.target": "/",
"net.peer.ip": "127.0.0.1",
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_500(self):
"http.method": "GET",
"http.server_name": "falconframework.org",
"http.scheme": "http",
"host.port": 80,
"net.host.port": 80,
"http.host": "falconframework.org",
"http.target": "/",
"net.peer.ip": "127.0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def expected_attributes(override_attributes):
"http.method": "GET",
"http.server_name": "localhost",
"http.scheme": "http",
"host.port": 80,
"net.host.port": 80,
"http.host": "localhost",
"http.target": "/",
"http.flavor": "1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ def set_trailing_metadata(self, *args, **kwargs):
def abort(self, code, details):
self.code = code
self.details = details
self._active_span.set_attribute("rpc.grpc.status_code", code.name)
self._active_span.set_attribute("rpc.grpc.status_code", code.value[0])
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
Status(
status_code=StatusCode.ERROR,
description="{}:{}".format(code, details),
)
)
return self._servicer_context.abort(code, details)

Expand All @@ -126,17 +129,25 @@ def set_code(self, code):
self.code = code
# use details if we already have it, otherwise the status description
details = self.details or code.value[1]
self._active_span.set_attribute("rpc.grpc.status_code", code.name)
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
self._active_span.set_attribute("rpc.grpc.status_code", code.value[0])
if code != grpc.StatusCode.OK:
self._active_span.set_status(
Status(
status_code=StatusCode.ERROR,
description="{}:{}".format(code, details),
)
)
return self._servicer_context.set_code(code)

def set_details(self, details):
self.details = details
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
if self.code != grpc.StatusCode.OK:
self._active_span.set_status(
Status(
status_code=StatusCode.ERROR,
description="{}:{}".format(self.code, details),
)
)
return self._servicer_context.set_details(details)


Expand Down Expand Up @@ -181,12 +192,20 @@ def _set_remote_context(self, servicer_context):

def _start_span(self, handler_call_details, context):

# standard attributes
attributes = {
"rpc.method": handler_call_details.method,
"rpc.system": "grpc",
"rpc.grpc.status_code": grpc.StatusCode.OK,
"rpc.grpc.status_code": grpc.StatusCode.OK.value[0],
}

# if we have details about the call, split into service and method
if handler_call_details.method:
service, method = handler_call_details.method.lstrip("/").split(
"/", 1
)
attributes.update({"rpc.method": method, "rpc.service": service})

# add some attributes from the metadata
metadata = dict(context.invocation_metadata())
if "user-agent" in metadata:
attributes["rpc.user_agent"] = metadata["user-agent"]
Expand All @@ -198,15 +217,15 @@ def _start_span(self, handler_call_details, context):
# * ipv4:10.2.1.1:57284,127.0.0.1:57284
#
try:
host, port = (
ip, port = (
context.peer().split(",")[0].split(":", 1)[1].rsplit(":", 1)
)
attributes.update({"net.peer.ip": ip, "net.peer.port": port})

# other telemetry sources convert this, so we will too
if host in ("[::1]", "127.0.0.1"):
host = "localhost"
# other telemetry sources add this, so we will too
if ip in ("[::1]", "127.0.0.1"):
attributes["net.peer.name"] = "localhost"

attributes.update({"net.peer.name": host, "net.peer.port": port})
except IndexError:
logger.warning("Failed to parse peer address '%s'", context.peer())

Expand Down
Loading

0 comments on commit 0e69d10

Please sign in to comment.