Skip to content

Commit 8ad211e

Browse files
committed
Add additional logging for errors
1 parent 42cbf91 commit 8ad211e

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

src/OpenTelemetry.Instrumentation.Kusto/Implementation/KustoInstrumentationEventSource.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,31 @@ public void EnrichmentException(string exception)
2828
{
2929
this.WriteEvent(1, exception);
3030
}
31+
32+
[Event(2, Message = "Trace record payload is NULL or has NULL message, record will not be processed.", Level = EventLevel.Warning)]
33+
public void NullPayload()
34+
{
35+
this.WriteEvent(2);
36+
}
37+
38+
[Event(3, Message = "Failed to find context for activity ID '{0}', operation data will not be recorded.", Level = EventLevel.Warning)]
39+
public void ContextNotFound(string activityId)
40+
{
41+
this.WriteEvent(3, activityId);
42+
}
43+
44+
[NonEvent]
45+
public void UnknownErrorProcessingTraceRecord(Exception ex)
46+
{
47+
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
48+
{
49+
this.UnknownErrorProcessingTraceRecord(ex.ToInvariantString());
50+
}
51+
}
52+
53+
[Event(4, Message = "Unknown error processing trace record, Exception: {0}", Level = EventLevel.Error)]
54+
public void UnknownErrorProcessingTraceRecord(string exception)
55+
{
56+
this.WriteEvent(4, exception);
57+
}
3158
}

src/OpenTelemetry.Instrumentation.Kusto/Implementation/KustoTraceRecordListener.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public override void Write(KustoUtils.TraceRecord record)
3333
{
3434
if (record?.Message is null)
3535
{
36+
KustoInstrumentationEventSource.Log.NullPayload();
3637
return;
3738
}
3839

@@ -41,17 +42,24 @@ public override void Write(KustoUtils.TraceRecord record)
4142
return;
4243
}
4344

44-
if (record.IsRequestStart())
45-
{
46-
this.HandleHttpRequestStart(record);
47-
}
48-
else if (record.IsActivityComplete())
45+
try
4946
{
50-
this.HandleActivityComplete(record);
47+
if (record.IsRequestStart())
48+
{
49+
this.HandleHttpRequestStart(record);
50+
}
51+
else if (record.IsActivityComplete())
52+
{
53+
this.HandleActivityComplete(record);
54+
}
55+
else if (record.IsException())
56+
{
57+
this.HandleException(record);
58+
}
5159
}
52-
else if (record.IsException())
60+
catch (Exception ex)
5361
{
54-
this.HandleException(record);
62+
KustoInstrumentationEventSource.Log.UnknownErrorProcessingTraceRecord(ex);
5563
}
5664
}
5765

@@ -200,6 +208,7 @@ private void HandleActivityComplete(KustoUtils.TraceRecord record)
200208
return context;
201209
}
202210

211+
KustoInstrumentationEventSource.Log.ContextNotFound(record.Activity.ActivityId.ToString());
203212
return null;
204213
}
205214

0 commit comments

Comments
 (0)