Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit ec72cd3

Browse files
authored
Fix logger.exception error when no exception present in Azure log exporter (#1006)
1 parent 31c3014 commit ec72cd3

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
## Unreleased
44

5+
- Fix `logger.exception` with no exception info throwing error
6+
([#1006](https://github.com/census-instrumentation/opencensus-python/pull/1006))
7+
8+
## 1.0.7
9+
Released 2021-01-25
10+
11+
- Hotfix
12+
([#1004](https://github.com/census-instrumentation/opencensus-python/pull/1004))
13+
514
## 1.0.6
615
Released 2021-01-14
716

817
- Disable heartbeat metrics in exporters
918
([#984](https://github.com/census-instrumentation/opencensus-python/pull/984))
1019
- Loosen instrumentation key validation to GUID
11-
([#984](https://github.com/census-instrumentation/opencensus-python/pull/984))
20+
([#986](https://github.com/census-instrumentation/opencensus-python/pull/986))
1221

1322
## 1.0.5
1423
Released 2020-10-13

contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,35 @@ def log_record_to_envelope(self, record):
170170
exctype, _value, tb = record.exc_info
171171
callstack = []
172172
level = 0
173-
for fileName, line, method, _text in traceback.extract_tb(tb):
174-
callstack.append({
175-
'level': level,
176-
'method': method,
177-
'fileName': fileName,
178-
'line': line,
179-
})
180-
level += 1
181-
callstack.reverse()
173+
has_full_stack = False
174+
exc_type = "N/A"
175+
message = self.format(record)
176+
if tb is not None:
177+
has_full_stack = True
178+
for fileName, line, method, _text in traceback.extract_tb(tb):
179+
callstack.append({
180+
'level': level,
181+
'method': method,
182+
'fileName': fileName,
183+
'line': line,
184+
})
185+
level += 1
186+
callstack.reverse()
187+
elif record.message:
188+
message = record.message
189+
190+
if exctype is not None:
191+
exc_type = exctype.__name__
182192

183193
envelope.name = 'Microsoft.ApplicationInsights.Exception'
194+
184195
data = ExceptionData(
185196
exceptions=[{
186197
'id': 1,
187198
'outerId': 0,
188-
'typeName': exctype.__name__,
189-
'message': self.format(record),
190-
'hasFullStack': True,
199+
'typeName': exc_type,
200+
'message': message,
201+
'hasFullStack': has_full_stack,
191202
'parsedStack': callstack,
192203
}],
193204
severityLevel=max(0, record.levelno - 1) // 10,

0 commit comments

Comments
 (0)