@@ -9,9 +9,22 @@ public static Activity AddMasaSupplement(this Activity activity, HttpRequest htt
9
9
{
10
10
activity . SetTag ( OpenTelemetryAttributeName . Http . FLAVOR , httpRequest . Protocol ) ;
11
11
activity . SetTag ( OpenTelemetryAttributeName . Http . SCHEME , httpRequest . Scheme ) ;
12
- activity . SetTag ( OpenTelemetryAttributeName . Http . CLIENT_IP , httpRequest . HttpContext ? . Connection ? . RemoteIpAddress ) ;
13
12
activity . SetTag ( OpenTelemetryAttributeName . Http . REQUEST_CONTENT_LENGTH , httpRequest . ContentLength ) ;
14
13
activity . SetTag ( OpenTelemetryAttributeName . Http . REQUEST_CONTENT_TYPE , httpRequest . ContentType ) ;
14
+ if ( httpRequest . Headers != null )
15
+ {
16
+ activity . SetTag ( OpenTelemetryAttributeName . Http . REQUEST_AUTHORIZATION , httpRequest . Headers . Authorization ) ;
17
+ activity . SetTag ( OpenTelemetryAttributeName . Http . REQUEST_USER_AGENT , httpRequest . Headers . UserAgent ) ;
18
+ var realIP = httpRequest . Headers [ "X-Real-IP" ] . ToString ( ) ;
19
+ realIP ??= httpRequest . HttpContext ! . Connection . RemoteIpAddress ! . ToString ( ) ;
20
+ activity . SetTag ( OpenTelemetryAttributeName . Http . CLIENT_IP , realIP ) ;
21
+ }
22
+
23
+ if ( ( httpRequest . HttpContext . User ? . Claims . Count ( ) ?? 0 ) > 0 )
24
+ {
25
+ activity . AddTag ( OpenTelemetryAttributeName . EndUser . ID , httpRequest . HttpContext . User ? . FindFirst ( "sub" ) ? . Value ?? string . Empty ) ;
26
+ activity . AddTag ( OpenTelemetryAttributeName . EndUser . USER_NICK_NAME , httpRequest . HttpContext . User ? . FindFirst ( "https://masastack.com/security/authentication/MasaNickName" ) ? . Value ?? string . Empty ) ;
27
+ }
15
28
if ( httpRequest . Body != null )
16
29
{
17
30
if ( ! httpRequest . Body . CanSeek )
@@ -26,7 +39,11 @@ public static Activity AddMasaSupplement(this Activity activity, HttpRequestMess
26
39
{
27
40
activity . SetTag ( OpenTelemetryAttributeName . Http . SCHEME , httpRequest . RequestUri ? . Scheme ) ;
28
41
activity . SetTag ( OpenTelemetryAttributeName . Host . NAME , Dns . GetHostName ( ) ) ;
29
-
42
+ if ( httpRequest . Headers != null )
43
+ {
44
+ activity . SetTag ( OpenTelemetryAttributeName . Http . REQUEST_AUTHORIZATION , httpRequest . Headers . Authorization ) ;
45
+ activity . SetTag ( OpenTelemetryAttributeName . Http . REQUEST_USER_AGENT , httpRequest . Headers . UserAgent ) ;
46
+ }
30
47
if ( httpRequest . Content != null )
31
48
{
32
49
SetActivityBody ( activity ,
@@ -48,7 +65,12 @@ public static Activity AddMasaSupplement(this Activity activity, HttpResponse ht
48
65
activity . AddTag ( OpenTelemetryAttributeName . EndUser . ID , httpResponse . HttpContext . User ? . FindFirst ( "sub" ) ? . Value ?? string . Empty ) ;
49
66
activity . AddTag ( OpenTelemetryAttributeName . EndUser . USER_NICK_NAME , httpResponse . HttpContext . User ? . FindFirst ( "https://masastack.com/security/authentication/MasaNickName" ) ? . Value ?? string . Empty ) ;
50
67
}
51
-
68
+ if ( httpResponse . HttpContext . Request != null && httpResponse . HttpContext . Request . Headers != null )
69
+ {
70
+ var realIP = httpResponse . HttpContext . Request . Headers [ "X-Real-IP" ] . ToString ( ) ;
71
+ realIP ??= httpResponse . HttpContext ! . Connection . RemoteIpAddress ! . ToString ( ) ;
72
+ activity . SetTag ( OpenTelemetryAttributeName . Http . CLIENT_IP , realIP ) ;
73
+ }
52
74
return activity ;
53
75
}
54
76
0 commit comments