Skip to content

Commit fc1ba91

Browse files
committed
Remove unnecessary TraceId/SpanId from log event properties
1 parent c00d3f9 commit fc1ba91

2 files changed

Lines changed: 6 additions & 30 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ By default, trace telemetry submits:
143143
- **rendered message** in trace's standard *message* property.
144144
- **severity** in trace's standard *severityLevel* property.
145145
- **timestamp** in trace's standard *timestamp* property.
146-
- **operation id** from `operationId` property, `TraceId` property, or `Activity.TraceId` (captured at log time).
146+
- **operation id** from `operationId` property, or the `LogEvent.TraceId` property.
147147
- **operation parent id** from `ParentSpanId` property.
148148
- **operation name** from `OperationName` property.
149149
- **component version** from `version` property.
@@ -155,7 +155,7 @@ Event telemetry submits:
155155
- **message template** as *event name*.
156156
- **renderedMessage** in *customDimensions*.
157157
- **timestamp** in event's standard *timestamp* property.
158-
- **operation id** from `operationId` property, `TraceId` property, or `Activity.TraceId` (captured at log time).
158+
- **operation id** from `operationId` property, or the `LogEvent.TraceId` property.
159159
- **operation parent id** from `ParentSpanId` property.
160160
- **operation name** from `OperationName` property.
161161
- **component version** from `version` property.
@@ -166,7 +166,7 @@ Exception telemetry submits:
166166
- **exception** as standard AI exception.
167167
- **severity** in trace's standard *severityLevel* property.
168168
- **timestamp** in trace's standard *timestamp* property.
169-
- **operation id** from `operationId` property, `TraceId` property, or `Activity.TraceId` (captured at log time).
169+
- **operation id** from `operationId` property, or the `LogEvent.TraceId` property.
170170
- **operation parent id** from `ParentSpanId` property.
171171
- **operation name** from `OperationName` property.
172172
- **component version** from `version` property.
@@ -349,7 +349,6 @@ Application Insight's operation id is set from the following sources in order of
349349

350350
1. `operationId` LogEvent property
351351
2. `TraceId` LogEvent property
352-
3. `Activity.TraceId` (captured at log time)
353352

354353
This can be set like so:
355354

@@ -387,7 +386,7 @@ The following LogEvent properties are mapped to Application Insights telemetry:
387386
| `operationId` | `Context.Operation.Id` | Overrides TraceId |
388387
| `version` | `Context.Component.Version` | |
389388

390-
Precedence for `Context.Operation.Id`: `operationId` property > `TraceId` property > `Activity.TraceId` (when both `operationId` and `TraceId` properties are absent).
389+
Precedence for `Context.Operation.Id`: `operationId` property > `TraceId` property (when both `operationId` and `TraceId` properties are absent).
391390

392391
## Using with Azure Functions
393392

src/Serilog.Sinks.ApplicationInsights/Sinks/ApplicationInsights/TelemetryConverters/TelemetryConverterBase.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.IO;
5-
using System.Linq;
1+
using System.Diagnostics;
62
using Microsoft.ApplicationInsights.Channel;
73
using Microsoft.ApplicationInsights.DataContracts;
84
using Serilog.Events;
@@ -39,21 +35,11 @@ public abstract class TelemetryConverterBase : ITelemetryConverter
3935
/// </summary>
4036
public const string OperationIdProperty = "operationId";
4137

42-
/// <summary>
43-
/// Property that is included when in log context, will be pushed out as AI trace id.
44-
/// </summary>
45-
public const string TraceIdProperty = "TraceId";
46-
4738
/// <summary>
4839
/// Property that is included when in log context, will be pushed out as AI parent span id.
4940
/// </summary>
5041
public const string ParentSpanIdProperty = "ParentSpanId";
5142

52-
/// <summary>
53-
/// Property that is included when in log context, will be pushed out as AI span id.
54-
/// </summary>
55-
public const string SpanIdProperty = "SpanId";
56-
5743
/// <summary>
5844
/// Property that is included when in log context, will be pushed out as AI operation name.
5945
/// </summary>
@@ -167,8 +153,6 @@ public void ForwardPropertiesToTelemetryProperties(LogEvent logEvent,
167153
// Operation.Id (TraceId)
168154
if (logEvent.Properties.TryGetValue(OperationIdProperty, out var operationIdProp))
169155
telemetry.Context.Operation.Id = operationIdProp.ToString().Trim('"');
170-
else if (logEvent.Properties.TryGetValue(TraceIdProperty, out var traceIdProp))
171-
telemetry.Context.Operation.Id = traceIdProp.ToString().Trim('"');
172156
else if (logEvent.TraceId is ActivityTraceId traceId)
173157
telemetry.Context.Operation.Id = traceId.ToHexString();
174158

@@ -181,14 +165,7 @@ public void ForwardPropertiesToTelemetryProperties(LogEvent logEvent,
181165
telemetry.Context.Operation.Name = operationNameProp.ToString().Trim('"');
182166

183167
// Set Id for RequestTelemetry and DependencyTelemetry
184-
if (logEvent.Properties.TryGetValue(SpanIdProperty, out var spanIdProp))
185-
{
186-
if (telemetry is RequestTelemetry req)
187-
req.Id = spanIdProp.ToString().Trim('"');
188-
else if (telemetry is DependencyTelemetry dep)
189-
dep.Id = spanIdProp.ToString().Trim('"');
190-
}
191-
else if (logEvent.SpanId is ActivitySpanId spanId)
168+
if (logEvent.SpanId is ActivitySpanId spanId)
192169
{
193170
if (telemetry is RequestTelemetry req)
194171
req.Id = spanId.ToHexString();

0 commit comments

Comments
 (0)