@@ -44,7 +44,12 @@ static Telemetry()
4444 // NOTE: this is not an entirely satisfactory way to tell events from commands apart.
4545 public const string Process = nameof ( Process ) ;
4646
47- public static Activity ? StartActivity ( Type type , string operation , [ CallerMemberName ] string ? member = default , [ CallerFilePath ] string ? file = default , [ CallerLineNumber ] int ? line = default )
47+ public static Activity ? StartCommandActivity ( Type type , object command ) => StartActivity ( type , Process , "Command" , command ) ;
48+
49+ public static Activity ? StartEventActivity ( Type type , object @event ) => StartActivity ( type , Publish , "Event" , @event ) ;
50+
51+ public static Activity ? StartActivity ( Type type , string operation , string ? property = default , object ? value = default ,
52+ [ CallerMemberName ] string ? member = default , [ CallerFilePath ] string ? file = default , [ CallerLineNumber ] int ? line = default )
4853 {
4954 if ( operation == Publish )
5055 events . Add ( 1 , new KeyValuePair < string , object ? > ( "Name" , type . FullName ) ) ;
@@ -55,7 +60,7 @@ static Telemetry()
5560 // Requirement is that the destination has low cardinality. In our case, the destination is
5661 // the logical operation being performed, such as "Execute", "Notify" or "Deliver". The
5762 // operation is actually the type being acted on (such as CreateUser -a command- or UserCreated -event).
58- return tracer . StartActivity ( ActivityKind . Producer , name : $ "{ operation } /{ type . FullName } ")
63+ var activity = tracer . CreateActivity ( $ "{ operation } /{ type . FullName } ", ActivityKind . Producer )
5964 ? . SetTag ( "code.function" , member )
6065 ? . SetTag ( "code.filepath" , file )
6166 ? . SetTag ( "code.lineno" , line )
@@ -65,6 +70,13 @@ static Telemetry()
6570 ? . SetTag ( "messaging.operation" , operation . ToLowerInvariant ( ) )
6671 ? . SetTag ( "messaging.protocol.name" , type . Assembly . GetName ( ) . Name )
6772 ? . SetTag ( "messaging.protocol.version" , type . Assembly . GetName ( ) . Version ? . ToString ( ) ?? "unknown" ) ;
73+
74+ if ( property != null && value != null )
75+ activity ? . SetCustomProperty ( property , value ) ;
76+
77+ activity ? . Start ( ) ;
78+
79+ return activity ;
6880 }
6981
7082 public static void RecordException ( this Activity ? activity , Exception e )
0 commit comments