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 2929
3030using System ;
3131using System . Collections . Generic ;
32+ #if ( NET462_OR_GREATER || NETSTANDARD2_0_OR_GREATER )
33+ using System . Diagnostics ;
34+ #endif
3235using System . IO ;
3336using System . Net ;
3437using System . Net . Security ;
@@ -293,6 +296,23 @@ protected virtual void PerformPostRequest(Stream postStream, Stream responseStre
293296 webRequest . Headers . Add ( header . Key , header . Value ) ;
294297 }
295298
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+
296316 using ( var str = webRequest . GetRequestStream ( ) )
297317 {
298318 postStream . CopyTo ( str ) ;
You can’t perform that action at this time.
0 commit comments