Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements for PR #1 #2

Merged
merged 53 commits into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e6392b6
Initial commit
dawallin May 26, 2016
26ce53e
Changed License to MIT
dawallin May 26, 2016
05e3379
.gitignore for visual studio project
dawallin May 26, 2016
5a7a752
Readme file added.
dawallin May 26, 2016
1a956bc
OpenTracing initial commit
dawallin May 26, 2016
e096e40
BasicTracer initial commit
dawallin May 26, 2016
f80f893
HttpClientCarrair initial commit
dawallin May 26, 2016
c2df056
Build status in readme
dawallin May 26, 2016
e0939a1
Removed SpanFactory
dawallin May 30, 2016
a5334d4
Removed SpanRecorder
dawallin May 30, 2016
9571514
Renamed BasicTracerContext to OpenTracingSpanContext (from BasicSpanC…
dawallin May 31, 2016
b90961a
Moved Tracer and Span implementations to BasicTracer (from OpenTracin…
dawallin May 31, 2016
d570a6a
Removed leaking context in StartSpanOptions.Parent.
dawallin May 31, 2016
b4387e5
Moved the OpenTracing Tracer and Span to root namespace.
dawallin Jun 1, 2016
6b0eb32
Moved the BasicTracer Tracer and Span to root namespace
dawallin Jun 1, 2016
8ff3c6c
Fixed unit test name (from copy paste typo error).
dawallin Jun 1, 2016
583e0df
Changed assembly name to simply OpenTracing.dll
dawallin Jun 2, 2016
668dfd4
Nuspec:s for OpenTracing and BasicTracer
dawallin Jun 2, 2016
af55c33
Clean up some namespaces.
dawallin Jun 2, 2016
5d4c4b9
Removed many generic type constraints on interfaces not needed.
dawallin Jun 4, 2016
68e7316
Moved TracerBuilder to BasicTracer
dawallin Jun 4, 2016
72a26c4
Moved SpanContext interfaces out from OpenTracing into BasicTracer.
dawallin Jun 4, 2016
2951da2
Simplified ContextMapper and removed TextMapFormat
dawallin Jun 5, 2016
97de99e
Merge branch 'InitialPR' into master
dawallin Jun 6, 2016
6656848
build script; rename to src (to better follow new Microsoft repos)
cwe1ss Aug 20, 2016
c253d97
since parent folder is now called "src", library folder can be "OpenT…
cwe1ss Aug 20, 2016
7189a71
nuget.exe not necessary with dotnet cli
cwe1ss Aug 20, 2016
094de2c
converted netstandard
cwe1ss Aug 20, 2016
435216f
refactoring
cwe1ss Aug 20, 2016
1e2352d
refactoring
cwe1ss Aug 20, 2016
ce43aa5
abstract base class for Span, singleton for NullTracer
cwe1ss Aug 20, 2016
d2d8ea8
SetTag now accepts an object
cwe1ss Aug 20, 2016
3f573ca
built-in tags are now regular ISpan extensions; BasicTracer compiles
cwe1ss Aug 21, 2016
705dec5
API refinements
cwe1ss Aug 21, 2016
1e6e7e2
tests succeed
cwe1ss Aug 21, 2016
ab72020
separate files for interfaces
cwe1ss Aug 21, 2016
62a4bdc
move tests to test folder
cwe1ss Aug 21, 2016
e532779
renamed IntegrationTests project to just tests
cwe1ss Aug 21, 2016
3f4c0b3
moved baggage dictionary into its own class
cwe1ss Aug 21, 2016
65885ee
removed SpanContext.GetBaggageItems() from interface
cwe1ss Aug 21, 2016
b79bb3c
naming etc
cwe1ss Aug 21, 2016
dc9c8fd
visual studio files
cwe1ss Aug 21, 2016
a29b4bd
stuff that accepts ISpanContext now also accepts ISpan
cwe1ss Aug 21, 2016
317f958
accidentally commited sample code; fixed powershell warnings
cwe1ss Aug 21, 2016
5db8b2d
PoC for AspNetCore integration
cwe1ss Aug 21, 2016
e052b65
big refactoring after gitter discussion; docs
cwe1ss Aug 23, 2016
5ea4551
renamed Log() to LogEvent() as of https://github.com/opentracing/open…
cwe1ss Aug 23, 2016
7d2cca2
TODOs
cwe1ss Aug 23, 2016
d39266a
removed get/setBaggageItem from SpanContext - as of opentracing.githu…
cwe1ss Aug 24, 2016
f4f1488
SpanBuilder from @dawallin
cwe1ss Aug 24, 2016
8c25747
SetOperationName(), BasicTracer: removed baggage key restrictions
cwe1ss Aug 29, 2016
e9c8ae8
Format/Carrier now almost equal to Java implementation
cwe1ss Aug 29, 2016
f55fdd6
AspNetCore is now in a separate branch - will move to a different rep…
cwe1ss Aug 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/OpenTracing.AspNetCore/HeaderDictionaryCarrier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace OpenTracing.AspNetCore
{
/// <summary>
/// A <see cref="ITextMapCarrier"/> which allows <see cref="IHeaderDictionary"/> implementations to be used as carrier objects.
/// A <see cref="ITextMap"/> which allows <see cref="IHeaderDictionary"/> implementations to be used as carrier objects.
/// </summary>
/// <remarks>
/// <see cref="IHeaderDictionary"/> is a multi-value dictionary. Since most other platforms represent http headers as regular
/// dictionaries, this carrier represents it as a regular dictionary to tracer implementations.</remarks>
public class HeaderDictionaryCarrier : ITextMapCarrier
public class HeaderDictionaryCarrier : ITextMap
{
private readonly IHeaderDictionary _headers;

Expand Down
13 changes: 0 additions & 13 deletions src/OpenTracing.BasicTracer/Propagation/IExtractCarrierHandler.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/OpenTracing.BasicTracer/Propagation/IInjectCarrierHandler.cs

This file was deleted.

10 changes: 4 additions & 6 deletions src/OpenTracing.BasicTracer/Propagation/TextMapCarrierHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

namespace OpenTracing.BasicTracer.Propagation
{
public class TextMapCarrierHandler :
IInjectCarrierHandler<ITextMapCarrier>,
IExtractCarrierHandler<ITextMapCarrier>
public class TextMapCarrierHandler
{
public void MapContextToCarrier(SpanContext context, ITextMapCarrier carrier)
public void MapContextToCarrier(SpanContext context, ITextMap carrier)
{
carrier.Add(BaggageKeys.TraceId, context.TraceId.ToString());
carrier.Add(BaggageKeys.SpanId, context.SpanId.ToString());
Expand All @@ -19,7 +17,7 @@ public void MapContextToCarrier(SpanContext context, ITextMapCarrier carrier)
}
}

public SpanContext MapCarrierToContext(ITextMapCarrier carrier)
public SpanContext MapCarrierToContext(ITextMap carrier)
{
// we can't create a reference without a trace-id
Guid? traceId = TryGetGuid(carrier, BaggageKeys.TraceId);
Expand Down Expand Up @@ -48,7 +46,7 @@ public SpanContext MapCarrierToContext(ITextMapCarrier carrier)
return new SpanContext(traceId.Value, spanId.Value, sampled, baggage);
}

private Guid? TryGetGuid(ITextMapCarrier carrier, string key)
private Guid? TryGetGuid(ITextMap carrier, string key)
{
string strValue = carrier.Get(key);

Expand Down
49 changes: 13 additions & 36 deletions src/OpenTracing.BasicTracer/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,32 @@ public ISpan StartSpan(string operationName, StartSpanOptions options)
return span;
}

public void Inject(ISpanContext spanContext, string format, IInjectCarrier carrier)
public void Inject<TCarrier>(ISpanContext spanContext, Format<TCarrier> format, TCarrier carrier)
{
switch (format)
{
case Formats.TextMap:
InjectTextMap(spanContext, carrier);
break;
// TODO add other formats
default:
throw new UnsupportedFormatException($"The format '{format}' is not supported.");
}
}
// TODO add other formats (and maybe don't use if/else :D )

private void InjectTextMap(ISpanContext spanContext, IInjectCarrier carrier)
{
var typedContext = (SpanContext)spanContext;

var textMapCarrier = carrier as ITextMapCarrier;
if (textMapCarrier != null)
if (format.Equals(Formats.TextMap))
{
_textMapCarrierHandler.MapContextToCarrier(typedContext, textMapCarrier);
return;
_textMapCarrierHandler.MapContextToCarrier(typedContext, (ITextMap) carrier);
}

throw new InvalidCarrierException($"The carrier '{carrier.GetType()}' is not supported for the format '{Formats.TextMap}'.");
}


public ISpanContext Extract(string format, IExtractCarrier carrier)
{
switch (format)
else
{
case Formats.TextMap:
return ExtractTextMap(carrier);
// TODO add other formats
default:
throw new UnsupportedFormatException($"The format '{format}' is not supported.");
throw new UnsupportedFormatException($"The format '{format}' is not supported.");
}
}

private ISpanContext ExtractTextMap(IExtractCarrier carrier)
public ISpanContext Extract<TCarrier>(Format<TCarrier> format, TCarrier carrier)
{
var textMapCarrier = carrier as ITextMapCarrier;
if (textMapCarrier != null)
// TODO add other formats (and maybe don't use if/else :D )

if (format.Equals(Formats.TextMap))
{
return _textMapCarrierHandler.MapCarrierToContext(textMapCarrier);
return _textMapCarrierHandler.MapCarrierToContext((ITextMap) carrier);
}

throw new InvalidCarrierException($"The carrier '{carrier.GetType()}' is not supported for the format '{Formats.TextMap}'.");
throw new UnsupportedFormatException($"The format '{format}' is not supported.");
}
}
}
4 changes: 2 additions & 2 deletions src/OpenTracing/Extensions/FormatBinaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void InjectBinary(this ITracer tracer, ISpanContext spanContext, b
throw new ArgumentNullException(nameof(tracer));
}

tracer.Inject(spanContext, Formats.Binary, new BinaryCarrier(data));
tracer.Inject(spanContext, Formats.Binary, data);
}

/// <summary>
Expand All @@ -51,7 +51,7 @@ public static ISpanContext ExtractBinary(this ITracer tracer, byte[] data)
throw new ArgumentNullException(nameof(tracer));
}

return tracer.Extract(Formats.Binary, new BinaryCarrier(data));
return tracer.Extract(Formats.Binary, data);
}
}
}
4 changes: 2 additions & 2 deletions src/OpenTracing/Extensions/FormatHttpHeadersExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void InjectHttpHeaders(this ITracer tracer, ISpanContext spanConte
throw new ArgumentNullException(nameof(tracer));
}

tracer.Inject(spanContext, Formats.HttpHeaders, new TextMapCarrier(headers));
tracer.Inject(spanContext, Formats.HttpHeaders, new DictionaryCarrier(headers));
}

/// <summary>
Expand Down Expand Up @@ -122,7 +122,7 @@ public static ISpanContext ExtractHttpHeaders(this ITracer tracer, IDictionary<s
throw new ArgumentNullException(nameof(tracer));
}

return tracer.Extract(Formats.HttpHeaders, new TextMapCarrier(headers));
return tracer.Extract(Formats.HttpHeaders, new DictionaryCarrier(headers));
}
}
}
10 changes: 5 additions & 5 deletions src/OpenTracing/Extensions/FormatTextMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ public static void InjectTextMap(this ITracer tracer, ISpanContext spanContext,
throw new ArgumentNullException(nameof(tracer));
}

tracer.Inject(spanContext, Formats.TextMap, new TextMapCarrier(data));
tracer.Inject(spanContext, Formats.TextMap, new DictionaryCarrier(data));
}

/// <summary>
/// Returns a new <see cref="ISpanContext"/> containing the baggage of the given <paramref name="dictionary"/>
/// Returns a new <see cref="ISpanContext"/> containing the baggage of the given <paramref name="data"/>
/// (using the format <see cref="Formats.HttpHeaders"/>), or null if there was no baggage found.
/// </summary>
/// <param name="tracer">A <see cref="ITracer"/> instance.</param>
/// <param name="dictionary">The dictionary will be used as a carrier for the propagation.</param>
public static ISpanContext ExtractTextMap(this ITracer tracer, IDictionary<string, string> dictionary)
/// <param name="data">The dictionary will be used as a carrier for the propagation.</param>
public static ISpanContext ExtractTextMap(this ITracer tracer, IDictionary<string, string> data)
{
if (tracer == null)
{
throw new ArgumentNullException(nameof(tracer));
}

return tracer.Extract(Formats.TextMap, new TextMapCarrier(dictionary));
return tracer.Extract(Formats.TextMap, new DictionaryCarrier(data));
}
}
}
4 changes: 2 additions & 2 deletions src/OpenTracing/ITracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public interface ITracer
/// <param name="spanContext">The <see cref="ISpanContext"/> instance to inject into the carrier.</param>
/// <param name="format">The format which should be used.</param>
/// <param name="carrier">See the documentation for the chosen <paramref name="format"/> for a description of the carrier object.</param>
void Inject(ISpanContext spanContext, string format, IInjectCarrier carrier);
void Inject<TCarrier>(ISpanContext spanContext, Format<TCarrier> format, TCarrier carrier);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/// <summary>
/// Returns a new <see cref="ISpanContext"/> containing the baggage of the given <paramref name="carrier"/>,
/// or null if there was no baggage found.
/// </summary>
/// <param name="format">The format which should be used.</param>
/// <param name="carrier">See the documentation for the chosen <paramref name="format"/> for a description of the carrier object</param>
ISpanContext Extract(string format, IExtractCarrier carrier);
ISpanContext Extract<TCarrier>(Format<TCarrier> format, TCarrier carrier);
}
}
22 changes: 0 additions & 22 deletions src/OpenTracing/InvalidCarrierException.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/OpenTracing/NullTracer/NullTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public ISpan StartSpan(string operationName, StartSpanOptions options = null)
return NullSpan.Instance;
}

public void Inject(ISpanContext spanContext, string format, IInjectCarrier carrier)
public void Inject<TCarrier>(ISpanContext spanContext, Format<TCarrier> format, TCarrier carrier)
{
}

public ISpanContext Extract(string format, IExtractCarrier carrier)
public ISpanContext Extract<TCarrier>(Format<TCarrier> format, TCarrier carrier)
{
return null;
}
Expand Down
24 changes: 0 additions & 24 deletions src/OpenTracing/Propagation/BinaryCarrier.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
namespace OpenTracing.Propagation
{
/// <summary>
/// The default <see cref="ITextMapCarrier"/> implementation which wraps an arbitrary <see cref="IDictionary{TKey,TValue}"/>.
/// The default <see cref="ITextMap"/> implementation which wraps an arbitrary <see cref="IDictionary{TKey,TValue}"/>.
/// </summary>
public class TextMapCarrier : ITextMapCarrier
public class DictionaryCarrier : ITextMap
{
private readonly IDictionary<string, string> _payload;

public TextMapCarrier(IDictionary<string, string> payload)
public DictionaryCarrier(IDictionary<string, string> payload)
{
if (payload == null)
{
Expand Down
59 changes: 59 additions & 0 deletions src/OpenTracing/Propagation/Format.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;

namespace OpenTracing.Propagation
{
/// <summary>
/// Format instances control the behavior of <see cref="ITracer.Inject" /> and <see cref="ITracer.Extract" />
/// (and also constrain the type of the carrier parameter to same).
/// </summary>
public class Format<TCarrier> : IEquatable<Format<TCarrier>>
{
/// <summary>
/// The unique name for this format.
/// </summary>
public string Name { get; }

public Format(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name));
}

Name = name;
}

/// <summary>
/// Two format instances are equal when they have the same <see cref="Name" />.
/// </summary>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;

return Equals(obj as Format<TCarrier>);
}

/// <summary>
/// Two format instances are equal when they have the same <see cref="Name" />.
/// </summary>
public bool Equals(Format<TCarrier> other)
{
if (other == null)
{
return false;
}

return string.Equals(Name, other.Name);
}

/// <summary>
/// Two format instances are equal when they have the same <see cref="Name" />.
/// </summary>
public override int GetHashCode()
{
return Name.GetHashCode();
}
}
}
Loading