This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
B3 single header implementation (#80)
* work on #66 - B3 single header implementation * first pass at B3 single header encoding * added first specs * finished all specs for verifying encoding * added first cut at B3 parsing engine * added parsing test cases * passed all parsing specs * fixed special case bugs with B3 Single Header parser * added specs to cover changes to B3Propagator * close #66 - finished implementing single header format
- Loading branch information
1 parent
f1f1fb4
commit 812ba83
Showing
6 changed files
with
551 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
242 changes: 242 additions & 0 deletions
242
src/Petabridge.Tracing.Zipkin.Tests/Propagation/B3SingleHeaderFormatterSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using FluentAssertions; | ||
using Petabridge.Tracing.Zipkin.Propagation; | ||
using Petabridge.Tracing.Zipkin.Tracers; | ||
using Xunit; | ||
using static Petabridge.Tracing.Zipkin.Propagation.B3SingleHeaderFormatter; | ||
|
||
namespace Petabridge.Tracing.Zipkin.Tests.Propagation | ||
{ | ||
public class B3SingleHeaderFormatterSpecs | ||
{ | ||
public B3SingleHeaderFormatterSpecs() | ||
{ | ||
Tracer = new MockZipkinTracer(propagtor: new B3Propagator()); | ||
} | ||
|
||
public readonly MockZipkinTracer Tracer; | ||
|
||
[Fact(DisplayName = "Should write 64bit B3 single format header without sampling")] | ||
public void ShouldWriteB3SingleHeaderWithoutSampling() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 64bit B3 single format header with sampling")] | ||
public void ShouldWriteB3SingleHeaderWithSampling() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, sampled:true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-1"); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 64bit B3 single format header with debug")] | ||
public void ShouldWriteB3SingleHeaderWithDebug() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, debug: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-d"); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 64bit B3 single format header with a parent id and sampling")] | ||
public void ShouldWriteB3SingleHeaderWithParentAndSampling() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, parentId:Tracer.IdProvider.NextSpanId(), sampled: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-1-" + context.ParentId); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 64bit B3 single format header with a parent id only")] | ||
public void ShouldWriteB3SingleHeaderWithParentIdOnly() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, parentId: "18974c44954cf23f"); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-" + context.ParentId); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 128bit B3 single format header without sampling")] | ||
public void ShouldWriteB3SingleHeaderWithoutSampling128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1,1), 3); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 128bit B3 single format header with sampling")] | ||
public void ShouldWriteB3SingleHeaderWithSampling128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, sampled:true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-1"); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 128bit B3 single format header with sampling and parent id (max length)")] | ||
public void ShouldWriteB3SingleHeaderWithSamplingAndParentId128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, parentId: Tracer.IdProvider.NextSpanId(), sampled: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-1-" + context.ParentId); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
[Fact(DisplayName = "Should write 128bit B3 single format header with parent id only")] | ||
public void ShouldWriteB3SingleHeaderWithParentIdOnly128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, parentId: Tracer.IdProvider.NextSpanId()); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
b3Header.Should().Be(context.TraceId + "-" + context.SpanId + "-" + context.ParentId); | ||
b3Header.Should().Be(Encoding.UTF8.GetString(WriteB3SingleFormatAsBytes(context))); | ||
} | ||
|
||
|
||
[Fact(DisplayName = "Should parse 128bit B3 single format header with sampling and parent id (max length)")] | ||
public void ShouldParseB3SingleHeaderWithSamplingAndParentId128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, parentId: Tracer.IdProvider.NextSpanId(), sampled: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 128bit B3 single format header with sampling")] | ||
public void ShouldParseB3SingleHeaderWithSampling128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, sampled: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 128bit B3 single format header with debug")] | ||
public void ShouldParseB3SingleHeaderWithDebug128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, debug: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 128bit B3 single format header")] | ||
public void ShouldParseB3SingleHeader128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 128bit B3 single format header with parentId only")] | ||
public void ShouldParseB3SingleHeaderParentIdOnly128Bit() | ||
{ | ||
var context = new SpanContext(new TraceId(1, 1), 3, parentId: "1aae83b1d7e325ce"); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 64bit B3 single format header with sampling and parent id")] | ||
public void ShouldParseB3SingleHeaderWithSamplingAndParentId() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, parentId: Tracer.IdProvider.NextSpanId(), sampled: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 64bit B3 single format header with sampling")] | ||
public void ShouldParseB3SingleHeaderWithSampling() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, sampled: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 64bit B3 single format header with debug")] | ||
public void ShouldParseB3SingleHeaderWithDebug() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, debug: true); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 64bit B3 single format header")] | ||
public void ShouldParseB3SingleHeader() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
|
||
[Fact(DisplayName = "Should parse 64bit B3 single format header with parent id")] | ||
public void ShouldParseB3SingleHeaderWithParentId() | ||
{ | ||
var context = new SpanContext(new TraceId(1), 3, parentId: Tracer.IdProvider.NextSpanId()); | ||
|
||
var b3Header = WriteB3SingleFormat(context); | ||
var b3HeaderParsed = ParseB3SingleFormat(b3Header); | ||
|
||
b3HeaderParsed.Should().Be(context); | ||
b3HeaderParsed.Sampled.Should().Be(context.Sampled); | ||
b3HeaderParsed.Debug.Should().Be(context.Debug); | ||
} | ||
} | ||
} |
Oops, something went wrong.