@@ -15,8 +15,10 @@ public class TelemetryApplicationInfoEnricher : ITelemetryActivityDataEnricher,
15
15
private readonly IEnumerable < ITelemetryApplicationInfoContributor > _telemetryApplicationInfoContributors ;
16
16
private readonly ITelemetryActivityStorage _telemetryActivityStorage ;
17
17
18
- public TelemetryApplicationInfoEnricher ( ITelemetrySessionTypeProvider telemetrySessionTypeProvider ,
19
- IEnumerable < ITelemetryApplicationInfoContributor > telemetryApplicationInfoContributors , ITelemetryActivityStorage telemetryActivityStorage )
18
+ public TelemetryApplicationInfoEnricher (
19
+ ITelemetrySessionTypeProvider telemetrySessionTypeProvider ,
20
+ IEnumerable < ITelemetryApplicationInfoContributor > telemetryApplicationInfoContributors ,
21
+ ITelemetryActivityStorage telemetryActivityStorage )
20
22
{
21
23
_telemetrySessionTypeProvider = telemetrySessionTypeProvider ;
22
24
_telemetryApplicationInfoContributors = telemetryApplicationInfoContributors ;
@@ -25,27 +27,64 @@ public TelemetryApplicationInfoEnricher(ITelemetrySessionTypeProvider telemetryS
25
27
26
28
public async Task EnrichAsync ( ActivityData activity )
27
29
{
28
- if ( activity . ContainsKey ( ActivityPropertyNames . Assembly ) && _telemetrySessionTypeProvider . SessionType == SessionType . ApplicationRuntime )
30
+ if ( ! ShouldEnrichActivity ( activity ) )
29
31
{
30
- if ( ! activity . TryGetValue ( ActivityPropertyNames . ProjectId , out var projectIdObj ) ||
31
- projectIdObj is not string projectIdStr ||
32
- ! Guid . TryParse ( projectIdStr , out var projectId ) )
32
+ return ;
33
+ }
34
+
35
+ var projectId = ExtractProjectId ( activity ) ;
36
+ if ( projectId == null )
37
+ {
38
+ return ;
39
+ }
40
+
41
+ try
42
+ {
43
+ if ( ! await _telemetryActivityStorage . ShouldAddApplicationInfoAsync ( projectId . Value ) )
33
44
{
34
45
return ;
35
46
}
36
47
37
- if ( ! await _telemetryActivityStorage . ShouldAddApplicationInfoAsync ( projectId ) )
48
+ await ContributeApplicationInfoAsync ( activity ) ;
49
+ activity . Remove ( ActivityPropertyNames . Assembly ) ;
50
+ await _telemetryActivityStorage . MarkApplicationInfoAsAddedAsync ( projectId . Value ) ;
51
+ }
52
+ catch
53
+ {
54
+ // ignored
55
+ }
56
+ }
57
+
58
+ private bool ShouldEnrichActivity ( ActivityData activity )
59
+ {
60
+ return activity . ContainsKey ( ActivityPropertyNames . Assembly ) &&
61
+ _telemetrySessionTypeProvider . SessionType == SessionType . ApplicationRuntime ;
62
+ }
63
+
64
+ private static Guid ? ExtractProjectId ( ActivityData activity )
65
+ {
66
+ if ( ! activity . TryGetValue ( ActivityPropertyNames . ProjectId , out var projectIdObj ) ||
67
+ projectIdObj is not string projectIdStr ||
68
+ ! Guid . TryParse ( projectIdStr , out var projectId ) )
69
+ {
70
+ return null ;
71
+ }
72
+
73
+ return projectId ;
74
+ }
75
+
76
+ private async Task ContributeApplicationInfoAsync ( ActivityData activity )
77
+ {
78
+ foreach ( var contributor in _telemetryApplicationInfoContributors )
79
+ {
80
+ try
38
81
{
39
- return ;
82
+ await contributor . ContributeAsync ( activity ) ;
40
83
}
41
-
42
- foreach ( var contributor in _telemetryApplicationInfoContributors )
84
+ catch
43
85
{
44
- await contributor . ContributeAsync ( activity ) ;
86
+ // ignored
45
87
}
46
-
47
- activity . Remove ( ActivityPropertyNames . Assembly ) ;
48
- await _telemetryActivityStorage . MarkApplicationInfoAsAddedAsync ( projectId ) ;
49
88
}
50
89
}
51
90
}
0 commit comments