5
5
using Microsoft . Extensions . DependencyInjection ;
6
6
using Uno . UI . RemoteControl . Server . Telemetry ;
7
7
8
- [ assembly: Telemetry ( "DevServer" , EventsPrefix = "uno/dev-server" ) ]
8
+ #if DEBUG
9
+ [ assembly: Telemetry ( "81286976-e3a4-49fb-b03b-30315092dbc4" , EventsPrefix = "uno/dev-server" ) ]
10
+ #else
11
+ [ assembly: Telemetry ( "9a44058e-1913-4721-a979-9582ab8bedce" , EventsPrefix = "uno/dev-server" ) ]
12
+ #endif
9
13
10
14
namespace Uno . UI . RemoteControl . Server . Helpers
11
15
{
@@ -20,8 +24,7 @@ public static IServiceCollection AddGlobalTelemetry(this IServiceCollection serv
20
24
// Register root telemetry session as singleton
21
25
services . AddSingleton < TelemetrySession > ( svc => new TelemetrySession
22
26
{
23
- SessionType = TelemetrySessionType . Root ,
24
- CreatedAt = DateTime . UtcNow
27
+ SessionType = TelemetrySessionType . Root , CreatedAt = DateTime . UtcNow
25
28
} ) ;
26
29
27
30
// Register global telemetry service as singleton
@@ -44,7 +47,8 @@ public static IServiceCollection AddConnectionTelemetry(this IServiceCollection
44
47
services . AddScoped < TelemetrySession > ( svc => CreateConnectionTelemetrySession ( svc ) ) ;
45
48
46
49
// Register connection-specific telemetry service as scoped
47
- services . AddScoped < ITelemetry > ( svc => CreateTelemetry ( typeof ( ITelemetry ) . Assembly , svc . GetRequiredService < TelemetrySession > ( ) . Id . ToString ( "N" ) ) ) ;
50
+ services . AddScoped < ITelemetry > ( svc => CreateTelemetry ( typeof ( ITelemetry ) . Assembly ,
51
+ svc . GetRequiredService < TelemetrySession > ( ) . Id . ToString ( "N" ) ) ) ;
48
52
services . AddScoped ( typeof ( ITelemetry < > ) , typeof ( TelemetryAdapter < > ) ) ;
49
53
50
54
return services ;
@@ -63,7 +67,8 @@ public static IServiceCollection AddTelemetry(this IServiceCollection services)
63
67
// Register TelemetrySession as scoped with connection context integration
64
68
services . AddScoped < TelemetrySession > ( svc => CreateTelemetrySession ( svc ) ) ;
65
69
66
- services . AddScoped < ITelemetry > ( svc => CreateTelemetry ( typeof ( ITelemetry ) . Assembly , svc . GetRequiredService < TelemetrySession > ( ) . Id . ToString ( "N" ) ) ) ;
70
+ services . AddScoped < ITelemetry > ( svc => CreateTelemetry ( typeof ( ITelemetry ) . Assembly ,
71
+ svc . GetRequiredService < TelemetrySession > ( ) . Id . ToString ( "N" ) ) ) ;
67
72
services . AddScoped ( typeof ( ITelemetry < > ) , typeof ( TelemetryAdapter < > ) ) ;
68
73
69
74
services . AddSingleton < ITelemetry > ( svc => CreateTelemetry ( typeof ( ITelemetry ) . Assembly ) ) ;
@@ -86,8 +91,10 @@ private static TelemetrySession CreateConnectionTelemetrySession(IServiceProvide
86
91
} ;
87
92
88
93
// Add connection metadata to the telemetry session
89
- session . AddMetadata ( "RemoteIpAddress" , TelemetryHashHelper . Hash ( connectionContext . RemoteIpAddress ? . ToString ( ) ?? "Unknown" ) ) ;
90
- session . AddMetadata ( "ConnectedAt" , connectionContext . ConnectedAt . ToString ( "yyyy-MM-dd HH:mm:ss UTC" , DateTimeFormatInfo . InvariantInfo ) ) ;
94
+ session . AddMetadata ( "RemoteIpAddress" ,
95
+ TelemetryHashHelper . Hash ( connectionContext . RemoteIpAddress ? . ToString ( ) ?? "Unknown" ) ) ;
96
+ session . AddMetadata ( "ConnectedAt" ,
97
+ connectionContext . ConnectedAt . ToString ( "yyyy-MM-dd HH:mm:ss UTC" , DateTimeFormatInfo . InvariantInfo ) ) ;
91
98
92
99
if ( ! string . IsNullOrEmpty ( connectionContext . UserAgent ) )
93
100
{
@@ -111,7 +118,8 @@ private static TelemetrySession CreateTelemetrySession(IServiceProvider svc)
111
118
var connectionContext = svc . GetService < ConnectionContext > ( ) ;
112
119
var session = new TelemetrySession
113
120
{
114
- SessionType = connectionContext != null ? TelemetrySessionType . Connection : TelemetrySessionType . Root ,
121
+ SessionType =
122
+ connectionContext != null ? TelemetrySessionType . Connection : TelemetrySessionType . Root ,
115
123
ConnectionId = connectionContext ? . ConnectionId ,
116
124
CreatedAt = DateTime . UtcNow
117
125
} ;
@@ -120,7 +128,9 @@ private static TelemetrySession CreateTelemetrySession(IServiceProvider svc)
120
128
if ( connectionContext != null )
121
129
{
122
130
session . AddMetadata ( "RemoteIpAddress" , connectionContext . RemoteIpAddress ? . ToString ( ) ?? "Unknown" ) ;
123
- session . AddMetadata ( "ConnectedAt" , connectionContext . ConnectedAt . ToString ( "yyyy-MM-dd HH:mm:ss UTC" , DateTimeFormatInfo . InvariantInfo ) ) ;
131
+ session . AddMetadata ( "ConnectedAt" ,
132
+ connectionContext . ConnectedAt . ToString ( "yyyy-MM-dd HH:mm:ss UTC" ,
133
+ DateTimeFormatInfo . InvariantInfo ) ) ;
124
134
125
135
if ( ! string . IsNullOrEmpty ( connectionContext . UserAgent ) )
126
136
{
@@ -142,31 +152,36 @@ private static TelemetrySession CreateTelemetrySession(IServiceProvider svc)
142
152
/// </summary>
143
153
private static ITelemetry CreateTelemetry ( Assembly asm , string ? sessionId = null )
144
154
{
155
+ // Get telemetry configuration first
156
+ if ( asm . GetCustomAttribute < TelemetryAttribute > ( ) is not { } config )
157
+ {
158
+ throw new InvalidOperationException ( $ "No telemetry config found for assembly { asm } .") ;
159
+ }
160
+
161
+ var eventsPrefix = config . EventsPrefix ?? $ "uno/{ asm . GetName ( ) . Name ? . ToLowerInvariant ( ) } ";
162
+
145
163
// Check for telemetry redirection environment variable
146
164
var telemetryFilePath = Environment . GetEnvironmentVariable ( "UNO_PLATFORM_TELEMETRY_FILE" ) ;
147
165
if ( ! string . IsNullOrEmpty ( telemetryFilePath ) )
148
166
{
149
- // New behavior: use contextual naming
167
+ // New behavior: use contextual naming with events prefix
150
168
if ( string . IsNullOrEmpty ( sessionId ) )
151
169
{
152
170
// Global telemetry - use contextual naming
153
- return new FileTelemetry ( telemetryFilePath , "global" ) ;
171
+ return new FileTelemetry ( telemetryFilePath , "global" , eventsPrefix ) ;
154
172
}
155
173
else
156
174
{
157
175
// Connection telemetry - use session ID as context
158
176
var shortSessionId = sessionId . Length > 8 ? sessionId . Substring ( 0 , 8 ) : sessionId ;
159
- return new FileTelemetry ( telemetryFilePath , $ "connection-{ shortSessionId } ") ;
177
+ return new FileTelemetry ( telemetryFilePath , $ "connection-{ shortSessionId } ", eventsPrefix ) ;
160
178
}
161
179
}
162
180
163
- if ( asm . GetCustomAttribute < TelemetryAttribute > ( ) is { } config )
164
- {
165
- var telemetry = new Uno . DevTools . Telemetry . Telemetry ( config . InstrumentationKey , config . EventsPrefix ?? $ "uno/{ asm . GetName ( ) . Name ? . ToLowerInvariant ( ) } ", asm , sessionId ) ;
166
- return new TelemetryWrapper ( telemetry ) ;
167
- }
168
-
169
- throw new InvalidOperationException ( $ "No telemetry config found for assembly { asm } .") ;
181
+ // Use normal telemetry
182
+ var telemetry =
183
+ new Uno . DevTools . Telemetry . Telemetry ( config . InstrumentationKey , eventsPrefix , asm , sessionId ) ;
184
+ return new TelemetryWrapper ( telemetry ) ;
170
185
}
171
186
}
172
187
}
0 commit comments