File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
ocaml/sdk-gen/csharp/autogen/src Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 29
29
30
30
using System ;
31
31
using System . Collections . Generic ;
32
+ #if ( NET462_OR_GREATER || NETSTANDARD2_0_OR_GREATER )
33
+ using System . Diagnostics ;
34
+ #endif
32
35
using System . IO ;
33
36
using System . Net ;
34
37
using System . Net . Security ;
@@ -293,6 +296,23 @@ protected virtual void PerformPostRequest(Stream postStream, Stream responseStre
293
296
webRequest . Headers . Add ( header . Key , header . Value ) ;
294
297
}
295
298
299
+ #if ( NET462_OR_GREATER || NETSTANDARD2_0_OR_GREATER )
300
+ // propagate W3C traceparent and tracestate
301
+ // HttpClient would do this automatically on .NET 5,
302
+ // and .NET 6 would provide even more control over this: https://blog.ladeak.net/posts/opentelemetry-net6-httpclient
303
+ // the caller must ensure that the activity is in W3C format (by inheritance or direct setting)
304
+ var activity = Activity . Current ;
305
+ if ( activity != null && activity . IdFormat == ActivityIdFormat . W3C )
306
+ {
307
+ webRequest . Headers . Add ( "traceparent" , activity . Id ) ;
308
+ var state = activity . TraceStateString ;
309
+ if ( state ? . Length > 0 )
310
+ {
311
+ webRequest . Headers . Add ( "tracestate" , state ) ;
312
+ }
313
+ }
314
+ #endif
315
+
296
316
using ( var str = webRequest . GetRequestStream ( ) )
297
317
{
298
318
postStream . CopyTo ( str ) ;
You can’t perform that action at this time.
0 commit comments