Skip to content

Commit

Permalink
Changes to support W3C style IDs and propagation (dotnet/corefx#33207)
Browse files Browse the repository at this point in the history
* First set of changes to support W3C style IDs and propagation

see https://w3c.github.io/trace-context

This is mostly for discussion purposes.

* Changed UseW3CFormat to be DefaultIdFormat

* Review feedback

* More comments.  Small Renames

* Added Sampling Support, Review feedback.

* Added placeholder for SetRecordingDesired

* Separated out the Sampling support into its own PR.

* Remove more sampling support

* Fix IsWC3Id -> IdFormat

* Added Sampling Support, Review feedback.

* Separated out the Sampling support into its own PR.

* Add ForceW3C option.

* Introduce ForceDefaultIdFormat

* Adding SpanId and TraceId support

* Change ulong->long in SpanID (probably temporary)

* Remove undesired file changes

* Fix up reference assembly.

Note complete because of questions about Span<byte>, but closer now.

* Turn on code that used Span<byte>

* Defer setting IDFormat until start.

This insures that the IDFormat property is either unknown or a given value (that never changes from there).

* More implementation, made the interface more uniform.

* Support to avoid using strings whenever possible

Basically Id, SpanId TraceId properties are set lazily and only converted lazily.

* Added some tests

* First round of testing (and bugfixes)

* More testing

* Added Equality operators

* Rename SpanId -> ActivitySpanId TraceId ->ActivityTraceId

* Add Comments

* Fix bad XML comment

* Review feedback

* Change AsBytes -> CopyTo

Lifetime issues prevent returning Span<T> (which is what AsBytes does.   Reverting to CopyTo instead.
Also added System.Memory ref in attempt to resolve build errors (that don't reproduce locally).

* Attempt to fix build break in netfx build

* Deal with Verification errors.

* Provide full namespace for SecuritySafeCriticalAttribute

* More securitySafeCritical annotations to fix test failures on desktop

* Another attempt on setting SecuritySafeCritical

* Remove the readonly ref (to avoid perf issue)

* Fix most  -buildAllConfigurations issues

* Tentative change to see if testing works if we ignore the older netstandard configs.

* Workaround package cycle involving DiagnosticSource and Memory

* Satisfy dangling System.Memory dangling reference in package tests

* Add notes to remove the workarounds when Unsafe is fixed.

* Review feedback

Uses Utf8 helpers where possible.


Commit migrated from dotnet/corefx@fa07e4f
  • Loading branch information
vancem authored Feb 26, 2019
1 parent 54cba79 commit 8df2d11
Show file tree
Hide file tree
Showing 7 changed files with 1,019 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,22 @@
<Value>.NETCoreApp;UAP</Value>
</ValidatePackageSuppression>
</ItemGroup>

<!-- This target is a work-around and should be removed by 6/2019 (by then a fixed version of System.Memory
should be available so that System.Memory does not reference NetStandard1.X)
See Eric St John for details. -->

<Target Name="RemoveSystemMemoryNetStandard1x" AfterTargets="GetNuGetPackageDependencies">
<!-- System.Memory is causing a cycle when used for netstandard1.x.
This is due to S.M referencing the NETStandard.Library metapackage for netstandard1.x
and that meta-package includes this package (System.Diagnostics.DiagnosticSource) in
its closure.
Remove the dependency for now until we can get a new build of System.Memory that doesn't
reference the NETStandard.Library metapackage. -->
<ItemGroup>
<Dependency Remove="@(Dependency)" Condition="'%(Identity)' == 'System.Memory' AND $([System.String]::new('%(TargetFramework)').StartsWith('netstandard1.'))" />
</ItemGroup>
</Target>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.targets))\Directory.Build.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<ProjectGuid>{3DF9A5D5-3D4B-4378-9B55-CFA6AC0114D9}</ProjectGuid>
<Configurations>net45-Debug;net45-Release;netfx-Debug;netfx-Release;netstandard-Debug;netstandard-Release;netstandard1.1-Debug;netstandard1.1-Release;netstandard1.3-Debug;netstandard1.3-Release</Configurations>
<CLSCompliant>false</CLSCompliant>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'net45' OR '$(TargetGroup)' == 'netfx'">
<DefineConstants>$(DefineConstants);ALLOW_PARTIALLY_TRUSTED_CALLERS</DefineConstants>
Expand All @@ -11,11 +12,20 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' != 'netstandard1.1'">
<Compile Include="System.Diagnostics.DiagnosticSourceActivity.cs" />
<Reference Include="System.Memory" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'net45' OR '$(TargetGroup)' == 'netfx'">
<Reference Include="mscorlib" />
</ItemGroup>

<ItemGroup Condition="'$(TargetGroup)' == 'net45'">
<Reference Include="System.Runtime" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netfx'">
<Reference Include="netstandard" />
</ItemGroup>

<ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.1' or '$(TargetGroup)' == 'netstandard1.3'">
<Reference Include="System.Runtime" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------

namespace System.Diagnostics
namespace System.Diagnostics
{
public partial class Activity
{
public partial class Activity
{
public Activity(string operationName) { }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> Baggage { get { throw null; } }
public static Activity Current
Expand All @@ -22,26 +22,80 @@ public static Activity Current
#endif
set { }
}
public static System.Diagnostics.ActivityIdFormat DefaultIdFormat { get { throw null; } set { } }
public System.TimeSpan Duration { get { throw null; } }
public static bool ForceDefaultIdFormat { get { throw null; } set { } }
public string Id { get { throw null; } }
public System.Diagnostics.ActivityIdFormat IdFormat { get { throw null; } }
public string OperationName { get { throw null; } }
public System.Diagnostics.Activity Parent { get { throw null; } }
public string ParentId { get { throw null; } }
public ref System.Diagnostics.ActivitySpanId ParentSpanId { get { throw null; } }
public string RootId { get { throw null; } }
public ref System.Diagnostics.ActivitySpanId SpanId { get { throw null; } }
public System.DateTime StartTimeUtc { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> Tags { get { throw null; } }
public ref System.Diagnostics.ActivityTraceId TraceId { get { throw null; } }
public string TraceStateString { get { throw null; } set { } }
public System.Diagnostics.Activity AddBaggage(string key, string value) { throw null; }
public System.Diagnostics.Activity AddTag(string key, string value) { throw null; }
public string GetBaggageItem(string key) { throw null; }
public System.Diagnostics.Activity SetEndTime(System.DateTime endTimeUtc) { throw null; }
public System.Diagnostics.Activity SetParentId(in System.Diagnostics.ActivityTraceId traceId, in System.Diagnostics.ActivitySpanId spanId) { throw null; }
public System.Diagnostics.Activity SetParentId(string parentId) { throw null; }
public System.Diagnostics.Activity SetStartTime(System.DateTime startTimeUtc) { throw null; }
public System.Diagnostics.Activity Start() { throw null; }
public void Stop() { }
}
public abstract partial class DiagnosticSource
{
public Activity StartActivity(Activity activity, object args) {throw null;}
public void StopActivity(Activity activity, object args) {}
}
}
public enum ActivityIdFormat : byte
{
Hierarchical = (byte)1,
Unknown = (byte)0,
W3C = (byte)2,
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public partial struct ActivitySpanId : IEquatable<ActivitySpanId>
{
private object _dummy;
private int _dummyPrimitive;
public ActivitySpanId(System.ReadOnlySpan<byte> idData, bool isUtf8Chars = false) { throw null; }
public ActivitySpanId(System.ReadOnlySpan<char> idData) { throw null; }
public string AsHexString { get { throw null; } }
public void CopyTo(System.Span<byte> destination) { }
public bool Equals(System.Diagnostics.ActivitySpanId spanId) { throw null; }
public override bool Equals(object obj) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Diagnostics.ActivitySpanId NewSpanId() { throw null; }
public static bool operator ==(in System.Diagnostics.ActivitySpanId spanId1, in System.Diagnostics.ActivitySpanId spandId2) { throw null; }
public static bool operator !=(in System.Diagnostics.ActivitySpanId spanId1, in System.Diagnostics.ActivitySpanId spandId2) { throw null; }
public override string ToString() { throw null; }
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public partial struct ActivityTraceId : IEquatable<ActivityTraceId>
{
private object _dummy;
private int _dummyPrimitive;
public ActivityTraceId(System.ReadOnlySpan<byte> idData, bool isUtf8Chars = false) { throw null; }
public ActivityTraceId(System.ReadOnlySpan<char> idData) { throw null; }
public string AsHexString { get { throw null; } }
public void CopyTo(System.Span<byte> destination) { }
public bool Equals(System.Diagnostics.ActivityTraceId traceId) { throw null; }
public override bool Equals(object obj) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Diagnostics.ActivityTraceId NewTraceId() { throw null; }
public static bool operator ==(in System.Diagnostics.ActivityTraceId traceId1, in System.Diagnostics.ActivityTraceId traceId2) { throw null; }
public static bool operator !=(in System.Diagnostics.ActivityTraceId traceId1, in System.Diagnostics.ActivityTraceId traceId2) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class DiagnosticSource
{
public Activity StartActivity(Activity activity, object args) { throw null; }
public void StopActivity(Activity activity, object args) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageTargetFramework Condition="'$(TargetGroup)' == 'netstandard1.1'">netstandard1.1;portable-net45+win8+wpa81</PackageTargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<BlockReflectionAttribute>false</BlockReflectionAttribute>
<CLSCompliant>false</CLSCompliant>
<Configurations>net45-Debug;net45-Release;net46-Debug;net46-Release;netcoreapp-Debug;netcoreapp-Release;netfx-Debug;netfx-Release;netstandard-Debug;netstandard-Release;netstandard1.1-Debug;netstandard1.1-Release;netstandard1.3-Debug;netstandard1.3-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard1.1' OR '$(TargetGroup)' == 'net45'">
Expand All @@ -25,6 +26,7 @@
<ItemGroup Condition=" '$(TargetGroup)' != 'netstandard1.1'">
<Compile Include="System\Diagnostics\Activity.cs" />
<Compile Include="System\Diagnostics\DiagnosticSourceActivity.cs" />
<Reference Include="System.Memory" />
<None Include="ActivityUserGuide.md" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetGroup)' != 'net45' And '$(TargetGroup)' != 'netstandard1.1'">
Expand All @@ -41,13 +43,14 @@
<ItemGroup Condition="'$(TargetGroup)' == 'net45' OR '$(TargetGroup)' == 'net46' OR '$(TargetGroup)' == 'netfx'">
<Compile Include="System\Diagnostics\HttpHandlerDiagnosticListener.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' != 'net46' AND '$(TargetGroup)' != 'netfx'">
<ItemGroup Condition="'$(TargetGroup)' != 'netfx'">
<Reference Include="System.Collections" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Reflection" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'net45' OR '$(TargetGroup)' == 'net46' OR '$(TargetGroup)' == 'netfx'">
Expand All @@ -56,4 +59,4 @@
<Reference Include="mscorlib" />
<Reference Include="System" />
</ItemGroup>
</Project>
</Project>
Loading

0 comments on commit 8df2d11

Please sign in to comment.