@@ -7,7 +7,7 @@ namespace Sentry.Protocol;
7
7
/// <summary>
8
8
/// Trace context data.
9
9
/// </summary>
10
- public class Trace : ITraceContext , ISentryJsonSerializable , ICloneable < Trace > , IUpdatable < Trace >
10
+ public class Trace : ITraceContext , ITraceContextInternal , ISentryJsonSerializable , ICloneable < Trace > , IUpdatable < Trace >
11
11
{
12
12
/// <summary>
13
13
/// Tells Sentry which type of context this is.
@@ -26,6 +26,21 @@ public class Trace : ITraceContext, ISentryJsonSerializable, ICloneable<Trace>,
26
26
/// <inheritdoc />
27
27
public string Operation { get ; set ; } = "" ;
28
28
29
+ /// <inheritdoc />
30
+ public string ? Origin
31
+ {
32
+ get => _origin ;
33
+ internal set
34
+ {
35
+ if ( ! OriginHelper . IsValidOrigin ( value ) )
36
+ {
37
+ throw new ArgumentException ( "Invalid origin" ) ;
38
+ }
39
+ _origin = value ;
40
+ }
41
+ }
42
+ private string ? _origin ;
43
+
29
44
/// <inheritdoc />
30
45
public string ? Description { get ; set ; }
31
46
@@ -46,6 +61,7 @@ public class Trace : ITraceContext, ISentryJsonSerializable, ICloneable<Trace>,
46
61
ParentSpanId = ParentSpanId ,
47
62
TraceId = TraceId ,
48
63
Operation = Operation ,
64
+ Origin = Origin ,
49
65
Status = Status ,
50
66
IsSampled = IsSampled
51
67
} ;
@@ -84,6 +100,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
84
100
writer . WriteSerializableIfNotNull ( "parent_span_id" , ParentSpanId ? . NullIfDefault ( ) , logger ) ;
85
101
writer . WriteSerializableIfNotNull ( "trace_id" , TraceId . NullIfDefault ( ) , logger ) ;
86
102
writer . WriteStringIfNotWhiteSpace ( "op" , Operation ) ;
103
+ writer . WriteString ( "origin" , Origin ?? Internal . OriginHelper . Manual ) ;
87
104
writer . WriteStringIfNotWhiteSpace ( "description" , Description ) ;
88
105
writer . WriteStringIfNotWhiteSpace ( "status" , Status ? . ToString ( ) . ToSnakeCase ( ) ) ;
89
106
@@ -99,6 +116,7 @@ public static Trace FromJson(JsonElement json)
99
116
var parentSpanId = json . GetPropertyOrNull ( "parent_span_id" ) ? . Pipe ( SpanId . FromJson ) ;
100
117
var traceId = json . GetPropertyOrNull ( "trace_id" ) ? . Pipe ( SentryId . FromJson ) ?? SentryId . Empty ;
101
118
var operation = json . GetPropertyOrNull ( "op" ) ? . GetString ( ) ?? "" ;
119
+ var origin = Internal . OriginHelper . TryParse ( json . GetPropertyOrNull ( "origin" ) ? . GetString ( ) ?? "" ) ;
102
120
var description = json . GetPropertyOrNull ( "description" ) ? . GetString ( ) ;
103
121
var status = json . GetPropertyOrNull ( "status" ) ? . GetString ( ) ? . Replace ( "_" , "" ) . ParseEnum < SpanStatus > ( ) ;
104
122
var isSampled = json . GetPropertyOrNull ( "sampled" ) ? . GetBoolean ( ) ;
@@ -109,6 +127,7 @@ public static Trace FromJson(JsonElement json)
109
127
ParentSpanId = parentSpanId ,
110
128
TraceId = traceId ,
111
129
Operation = operation ,
130
+ Origin = origin ,
112
131
Description = description ,
113
132
Status = status ,
114
133
IsSampled = isSampled
0 commit comments