Skip to content

Commit 81f97ca

Browse files
Synthetic Source internal, dependency operation name, enhance event message (#3087)
* SyntheticSource internal, event source improvements * Syn Dependency operation name. * Update public api
1 parent f6d08d1 commit 81f97ca

File tree

8 files changed

+104
-19
lines changed

8 files changed

+104
-19
lines changed

.publicApi/Microsoft.ApplicationInsights.dll/Stable/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ Microsoft.ApplicationInsights.Extensibility.Implementation.LocationContext.Ip.se
138138
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationContext
139139
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationContext.Name.get -> string
140140
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationContext.Name.set -> void
141-
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationContext.SyntheticSource.get -> string
142-
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationContext.SyntheticSource.set -> void
143141
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationTelemetry
144142
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationTelemetry.OperationTelemetry() -> void
145143
Microsoft.ApplicationInsights.Extensibility.Implementation.OperationTelemetry.Sanitize() -> void

BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/OperationContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public string Name
2929
/// <summary>
3030
/// Gets or sets the application-defined operation SyntheticSource.
3131
/// </summary>
32-
public string SyntheticSource
32+
internal string SyntheticSource
3333
{
3434
get { return string.IsNullOrEmpty(this.syntheticSource) ? null : this.syntheticSource; }
3535
set { this.syntheticSource = value; }

BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ public void TrackDependency(DependencyTelemetry telemetry)
645645
dependencyTelemetryActivity.SetTag(SemanticConventions.AttributeMicrosoftDependencyResultCode, telemetry.ResultCode);
646646
}
647647

648+
if (!string.IsNullOrEmpty(telemetry.Context?.Operation?.Name))
649+
{
650+
dependencyTelemetryActivity.SetTag(SemanticConventions.AttributeMicrosoftOperationName, telemetry.Context.Operation.Name);
651+
}
652+
648653
// Add GlobalProperties first (lower priority)
649654
if (this.Context?.GlobalPropertiesValue != null)
650655
{

NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensibility/Implementation/Tracing/AspNetCoreEventSource.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,57 @@ private AspNetCoreEventSource()
3131
}
3232

3333
/// <summary>
34-
/// Logs an event for when generic error occur within the SDK.
34+
/// Logs an event for when adding Application Insights telemetry fails.
3535
/// </summary>
3636
[Event(
3737
1,
3838
Keywords = Keywords.Diagnostics,
39-
Message = "An error has occurred which may prevent application insights from functioning. Error message: '{0}' ",
39+
Message = "Failed to add Application Insights telemetry. Error: '{0}'",
4040
Level = EventLevel.Error)]
41-
public void LogError(string errorMessage, string appDomainName = "Incorrect")
41+
public void FailedToAddTelemetry(string errorMessage, string appDomainName = "Incorrect")
4242
{
4343
this.WriteEvent(1, errorMessage, this.applicationNameProvider.Name);
4444
}
4545

46+
/// <summary>
47+
/// Logs an event for when an invalid TracesPerSecond value is configured.
48+
/// </summary>
49+
[Event(
50+
2,
51+
Keywords = Keywords.Diagnostics,
52+
Message = "Invalid TracesPerSecond value '{0}'. Value must be at least 0. Using default value.",
53+
Level = EventLevel.Warning)]
54+
public void InvalidTracesPerSecondConfigured(double tracesPerSecond, string appDomainName = "Incorrect")
55+
{
56+
this.WriteEvent(2, tracesPerSecond, this.applicationNameProvider.Name);
57+
}
58+
59+
/// <summary>
60+
/// Logs an event for when an invalid SamplingRatio value is configured.
61+
/// </summary>
62+
[Event(
63+
3,
64+
Keywords = Keywords.Diagnostics,
65+
Message = "Invalid SamplingRatio value '{0}'. Value must be between 0.0 and 1.0. Using default value.",
66+
Level = EventLevel.Warning)]
67+
public void InvalidSamplingRatioConfigured(float samplingRatio, string appDomainName = "Incorrect")
68+
{
69+
this.WriteEvent(3, samplingRatio, this.applicationNameProvider.Name);
70+
}
71+
72+
/// <summary>
73+
/// Logs an event for when telemetry configuration fails.
74+
/// </summary>
75+
[Event(
76+
4,
77+
Keywords = Keywords.Diagnostics,
78+
Message = "Failed to configure telemetry. Error: '{0}'",
79+
Level = EventLevel.Error)]
80+
public void TelemetryConfigurationFailure(string errorMessage, string appDomainName = "Incorrect")
81+
{
82+
this.WriteEvent(4, errorMessage, this.applicationNameProvider.Name);
83+
}
84+
4685
/// <summary>
4786
/// Keywords for the AspNetEventSource.
4887
/// </summary>

NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
105105
}
106106
catch (Exception e)
107107
{
108-
AspNetCoreEventSource.Instance.LogError(e.ToInvariantString());
108+
AspNetCoreEventSource.Instance.FailedToAddTelemetry(e.ToInvariantString());
109109
return services;
110110
}
111111
}
@@ -243,7 +243,7 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
243243
}
244244
else
245245
{
246-
AspNetCoreEventSource.Instance.LogError($"Invalid TracesPerSecond value '{serviceOptions.TracesPerSecond.Value}'. Value must be at least 0. Using default value.");
246+
AspNetCoreEventSource.Instance.InvalidTracesPerSecondConfigured(serviceOptions.TracesPerSecond.Value);
247247
}
248248
}
249249

@@ -259,7 +259,7 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
259259
}
260260
else
261261
{
262-
AspNetCoreEventSource.Instance.LogError($"Invalid SamplingRatio value '{serviceOptions.SamplingRatio.Value}'. Value must be between 0.0 and 1.0. Using default value.");
262+
AspNetCoreEventSource.Instance.InvalidSamplingRatioConfigured(serviceOptions.SamplingRatio.Value);
263263
}
264264
}
265265

NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(th
102102
}
103103
catch (Exception e)
104104
{
105-
WorkerServiceEventSource.Instance.LogError(e.ToInvariantString());
105+
WorkerServiceEventSource.Instance.FailedToAddTelemetry(e.ToInvariantString());
106106
return services;
107107
}
108108
}
@@ -231,7 +231,7 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
231231
}
232232
else
233233
{
234-
WorkerServiceEventSource.Instance.LogError($"Invalid TracesPerSecond value '{serviceOptions.TracesPerSecond.Value}'. Value must be at least 0. Using default value.");
234+
WorkerServiceEventSource.Instance.InvalidTracesPerSecondConfigured(serviceOptions.TracesPerSecond.Value);
235235
}
236236
}
237237

@@ -247,7 +247,7 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
247247
}
248248
else
249249
{
250-
WorkerServiceEventSource.Instance.LogError($"Invalid SamplingRatio value '{serviceOptions.SamplingRatio.Value}'. Value must be between 0.0 and 1.0. Using default value.");
250+
WorkerServiceEventSource.Instance.InvalidSamplingRatioConfigured(serviceOptions.SamplingRatio.Value);
251251
}
252252
}
253253

NETCORE/src/Microsoft.ApplicationInsights.WorkerService/Implementation/Tracing/WorkerServiceEventSource.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,57 @@ private WorkerServiceEventSource()
2929
}
3030

3131
/// <summary>
32-
/// Logs error message.
32+
/// Logs an event for when adding Application Insights telemetry fails.
3333
/// </summary>
34-
/// <param name="message">Message.</param>
34+
/// <param name="errorMessage">Error message.</param>
3535
/// <param name="appDomainName">An ignored placeholder to make EventSource happy.</param>
36-
[Event(1, Message = "An error has occurred which may prevent application insights from functioning. Error message: '{0}'", Level = EventLevel.Error)]
37-
public void LogError(string message, string appDomainName = "Incorrect")
36+
[Event(
37+
1,
38+
Keywords = Keywords.Diagnostics,
39+
Message = "Failed to add Application Insights telemetry. Error: '{0}'",
40+
Level = EventLevel.Error)]
41+
public void FailedToAddTelemetry(string errorMessage, string appDomainName = "Incorrect")
3842
{
39-
this.WriteEvent(1, message, this.applicationNameProvider.Name);
43+
this.WriteEvent(1, errorMessage, this.applicationNameProvider.Name);
44+
}
45+
46+
/// <summary>
47+
/// Logs an event for when an invalid TracesPerSecond value is configured.
48+
/// </summary>
49+
[Event(
50+
2,
51+
Keywords = Keywords.Diagnostics,
52+
Message = "Invalid TracesPerSecond value '{0}'. Value must be at least 0. Using default value.",
53+
Level = EventLevel.Warning)]
54+
public void InvalidTracesPerSecondConfigured(double tracesPerSecond, string appDomainName = "Incorrect")
55+
{
56+
this.WriteEvent(2, tracesPerSecond, this.applicationNameProvider.Name);
57+
}
58+
59+
/// <summary>
60+
/// Logs an event for when an invalid SamplingRatio value is configured.
61+
/// </summary>
62+
[Event(
63+
3,
64+
Keywords = Keywords.Diagnostics,
65+
Message = "Invalid SamplingRatio value '{0}'. Value must be between 0.0 and 1.0. Using default value.",
66+
Level = EventLevel.Warning)]
67+
public void InvalidSamplingRatioConfigured(float samplingRatio, string appDomainName = "Incorrect")
68+
{
69+
this.WriteEvent(3, samplingRatio, this.applicationNameProvider.Name);
70+
}
71+
72+
/// <summary>
73+
/// Logs an event for when telemetry configuration fails.
74+
/// </summary>
75+
[Event(
76+
4,
77+
Keywords = Keywords.Diagnostics,
78+
Message = "Failed to configure telemetry. Error: '{0}'",
79+
Level = EventLevel.Error)]
80+
public void TelemetryConfigurationFailure(string errorMessage, string appDomainName = "Incorrect")
81+
{
82+
this.WriteEvent(4, errorMessage, this.applicationNameProvider.Name);
4083
}
4184

4285
/// <summary>

NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ internal static void AddTelemetryConfiguration(
6363
catch (Exception ex)
6464
{
6565
#if AI_ASPNETCORE_WEB
66-
AspNetCoreEventSource.Instance.LogError(ex.ToInvariantString());
66+
AspNetCoreEventSource.Instance.TelemetryConfigurationFailure(ex.ToInvariantString());
6767
#else
68-
WorkerServiceEventSource.Instance.LogError(ex.ToInvariantString());
68+
WorkerServiceEventSource.Instance.TelemetryConfigurationFailure(ex.ToInvariantString());
6969
#endif
7070
}
7171
}

0 commit comments

Comments
 (0)