Skip to content

Commit

Permalink
Merge branch 'main' into 2991-client-key-and-certificate-for-otlp-exp…
Browse files Browse the repository at this point in the history
…orters
  • Loading branch information
lzchen authored Aug 19, 2024
2 parents c48d4ee + ea4616d commit e426963
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Make log sdk add `exception.message` to logRecord for exceptions whose argument
is an exception not a string message
([#4122](https://github.com/open-telemetry/opentelemetry-python/pull/4122))
- Fix use of `link.attributes.dropped`, which may not exist
([#4119](https://github.com/open-telemetry/opentelemetry-python/pull/4119))
- Running mypy on SDK resources
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and [**Maintainer**](https://github.com/open-telemetry/community/blob/main/commu

Before you can contribute, you will need to sign the [Contributor License Agreement](https://docs.linuxfoundation.org/lfx/easycla/contributors).

Please also read the [OpenTelemetry Contributor Guide](https://github.com/open-telemetry/community/blob/main/CONTRIBUTING.md).
Please also read the [OpenTelemetry Contributor Guide](https://github.com/open-telemetry/community/blob/main/guides/contributor/README.md).

# Find your right repo

Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-api/src/opentelemetry/util/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
# A value contains a URL-encoded UTF-8 string. The encoded form can contain any
# printable US-ASCII characters (0x20-0x7f) other than SP, DEL, and ",;/
_VALUE_FORMAT = r"[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
# Like above with SP included
_LIBERAL_VALUE_FORMAT = r"[\x20\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
# A key-value is key=value, with optional whitespace surrounding key and value
_KEY_VALUE_FORMAT = rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_VALUE_FORMAT}{_OWS}"

_HEADER_PATTERN = compile(_KEY_VALUE_FORMAT)
_LIBERAL_HEADER_PATTERN = compile(
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}[\w ]*{_OWS}"
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_LIBERAL_VALUE_FORMAT}{_OWS}"
)
_DELIMITER_PATTERN = compile(r"[ \t]*,[ \t]*")

Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-api/tests/util/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def test_parse_env_headers_liberal(self):
inp = self._common_test_cases() + [
# valid header value
("key=value othervalue", [("key", "value othervalue")], False),
(
"key=value Other_Value==",
[("key", "value Other_Value==")],
False,
),
]
for case_ in inp:
headers, expected, warn = case_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ def _get_attributes(record: logging.LogRecord) -> Attributes:
if exctype is not None:
attributes[SpanAttributes.EXCEPTION_TYPE] = exctype.__name__
if value is not None and value.args:
attributes[SpanAttributes.EXCEPTION_MESSAGE] = value.args[0]
attributes[SpanAttributes.EXCEPTION_MESSAGE] = str(
value.args[0]
)
if tb is not None:
# https://github.com/open-telemetry/opentelemetry-specification/blob/9fa7c656b26647b27e485a6af7e38dc716eba98a/specification/trace/semantic_conventions/exceptions.md#stacktrace-representation
attributes[SpanAttributes.EXCEPTION_STACKTRACE] = "".join(
Expand Down
35 changes: 34 additions & 1 deletion opentelemetry-sdk/tests/logs/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,41 @@ def test_log_record_exception(self):
self.assertTrue("division by zero" in stack_trace)
self.assertTrue(__file__ in stack_trace)

def test_log_record_recursive_exception(self):
"""Exception information will be included in attributes even though it is recursive"""
processor, logger = set_up_test_logging(logging.ERROR)

try:
raise ZeroDivisionError(
ZeroDivisionError(ZeroDivisionError("division by zero"))
)
except ZeroDivisionError:
with self.assertLogs(level=logging.ERROR):
logger.exception("Zero Division Error")

log_record = processor.get_log_record(0)

self.assertIsNotNone(log_record)
self.assertEqual(log_record.body, "Zero Division Error")
self.assertEqual(
log_record.attributes[SpanAttributes.EXCEPTION_TYPE],
ZeroDivisionError.__name__,
)
self.assertEqual(
log_record.attributes[SpanAttributes.EXCEPTION_MESSAGE],
"division by zero",
)
stack_trace = log_record.attributes[
SpanAttributes.EXCEPTION_STACKTRACE
]
self.assertIsInstance(stack_trace, str)
self.assertTrue("Traceback" in stack_trace)
self.assertTrue("ZeroDivisionError" in stack_trace)
self.assertTrue("division by zero" in stack_trace)
self.assertTrue(__file__ in stack_trace)

def test_log_exc_info_false(self):
"""Exception information will be included in attributes"""
"""Exception information will not be included in attributes"""
processor, logger = set_up_test_logging(logging.NOTSET)

try:
Expand Down

0 comments on commit e426963

Please sign in to comment.