Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tracingplane-go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cld
tracing
tracingplane-go
Commits
b72617bd
Commit
b72617bd
authored
Oct 20, 2017
by
Jonathan Mace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Zipkin example and some new primitives
parent
005f1cab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
195 additions
and
0 deletions
+195
-0
bdl/primitives.go
bdl/primitives.go
+28
-0
examples/zipkin.go
examples/zipkin.go
+127
-0
examples/zipkin_test.go
examples/zipkin_test.go
+40
-0
No files found.
bdl/primitives.go
View file @
b72617bd
...
...
@@ -90,4 +90,32 @@ func ReadInt64Fixed(bytes []byte) *int64 {
func
WriteInt64Fixed
(
v
int64
)
[]
byte
{
return
WriteUint64Fixed
(
uint64
(
v
))
}
func
ReadBool
(
bytes
[]
byte
)
*
bool
{
var
value
bool
switch
{
case
len
(
bytes
)
!=
1
:
return
nil
case
bytes
[
0
]
==
byte
(
0
)
:
value
=
false
case
bytes
[
0
]
==
byte
(
1
)
:
value
=
true
default
:
return
nil
}
return
&
value
}
func
WriteBool
(
v
bool
)
[]
byte
{
if
v
{
return
[]
byte
{
1
}
}
return
[]
byte
{
0
}
}
func
ReadTaint
(
bytes
[]
byte
)
*
bool
{
boolValue
:=
ReadBool
(
bytes
)
if
boolValue
==
nil
{
return
nil
}
*
boolValue
=
!*
boolValue
return
boolValue
}
func
WriteTaint
(
v
bool
)
[]
byte
{
if
v
{
return
[]
byte
{
0
}
}
return
[]
byte
{
1
}
}
\ No newline at end of file
examples/zipkin.go
0 → 100644
View file @
b72617bd
package
examples
import
(
"github.com/tracingplane/tracingplane-go/bdl"
"github.com/tracingplane/tracingplane-go/baggageprotocol"
"github.com/tracingplane/tracingplane-go/atomlayer"
"sort"
)
// An example of a class that would be generated by BDL for Zipkin
type
ZipkinMetadata
struct
{
traceID
*
int64
// sfixed64 traceID = 0;
spanID
*
int64
// sfixed64 spanID = 1;
parentSpanID
*
int64
// sfixed64 parentSpanID = 2;
sampled
*
bool
// taint sampled = 3;
tags
map
[
string
](
string
)
// map<string, string> tags = 4;
overflowed
bool
unknown
[]
atomlayer
.
Atom
}
func
(
zipkinMetadata
*
ZipkinMetadata
)
Read
(
r
*
baggageprotocol
.
Reader
)
{
// traceID
if
r
.
EnterIndexed
(
0
)
{
zipkinMetadata
.
traceID
=
bdl
.
ReadInt64Fixed
(
r
.
Next
());
r
.
Exit
()
}
// spanID
if
r
.
EnterIndexed
(
1
)
{
zipkinMetadata
.
spanID
=
bdl
.
ReadInt64Fixed
(
r
.
Next
());
r
.
Exit
()
}
// parentSpanID
if
r
.
EnterIndexed
(
2
)
{
zipkinMetadata
.
parentSpanID
=
bdl
.
ReadInt64Fixed
(
r
.
Next
());
r
.
Exit
()
}
// sampled
if
r
.
EnterIndexed
(
3
)
{
zipkinMetadata
.
sampled
=
bdl
.
ReadTaint
(
r
.
Next
())
r
.
Exit
()
}
// tags
if
r
.
EnterIndexed
(
4
)
{
zipkinMetadata
.
tags
=
make
(
map
[
string
](
string
))
for
{
key
:=
r
.
Enter
()
if
key
==
nil
{
break
}
value
:=
r
.
Next
()
if
value
!=
nil
{
tagsKey
:=
string
(
key
[
1
:
])
tagsValue
:=
string
(
value
)
zipkinMetadata
.
tags
[
tagsKey
]
=
tagsValue
}
r
.
Exit
()
}
}
// Overflow
zipkinMetadata
.
overflowed
=
r
.
Overflowed
}
func
(
zipkinMetadata
*
ZipkinMetadata
)
Write
(
w
*
baggageprotocol
.
Writer
)
{
// traceID
if
zipkinMetadata
.
traceID
!=
nil
{
w
.
Enter
(
0
)
w
.
Write
(
bdl
.
WriteInt64Fixed
(
*
zipkinMetadata
.
traceID
))
w
.
Exit
()
}
// spanID
if
zipkinMetadata
.
spanID
!=
nil
{
w
.
Enter
(
1
)
w
.
Write
(
bdl
.
WriteInt64Fixed
(
*
zipkinMetadata
.
spanID
))
w
.
Exit
()
}
// parentSpanID
if
zipkinMetadata
.
parentSpanID
!=
nil
{
w
.
Enter
(
2
)
w
.
Write
(
bdl
.
WriteInt64Fixed
(
*
zipkinMetadata
.
parentSpanID
))
w
.
Exit
()
}
// sampled
if
zipkinMetadata
.
sampled
!=
nil
{
w
.
Enter
(
3
)
w
.
Write
(
bdl
.
WriteTaint
(
*
zipkinMetadata
.
sampled
))
w
.
Exit
()
}
// tags
if
len
(
zipkinMetadata
.
tags
)
>
0
{
var
tagKeys
[]
atomlayer
.
Atom
for
tagKey
:=
range
(
zipkinMetadata
.
tags
)
{
tagKeys
=
append
(
tagKeys
,
atomlayer
.
Atom
(
tagKey
))
}
sort
.
Sort
(
baggageprotocol
.
LexicographicAtomSorter
(
tagKeys
))
for
_
,
tagKey
:=
range
(
tagKeys
)
{
tagValue
:=
[]
byte
(
zipkinMetadata
.
tags
[
string
(
tagKey
)])
w
.
EnterKey
(
tagKey
)
w
.
Write
(
tagValue
)
w
.
Exit
()
}
}
// Overflow
if
zipkinMetadata
.
overflowed
{
w
.
MarkOverflow
()
}
}
func
(
zipkinMetadata
*
ZipkinMetadata
)
SetUnprocessedAtoms
(
atoms
[]
atomlayer
.
Atom
)
{
zipkinMetadata
.
unknown
=
atoms
}
func
(
zipkinMetadata
*
ZipkinMetadata
)
GetUnprocessedAtoms
()
[]
atomlayer
.
Atom
{
return
zipkinMetadata
.
unknown
}
\ No newline at end of file
examples/zipkin_test.go
0 → 100644
View file @
b72617bd
package
examples
import
(
"github.com/stretchr/testify/assert"
"github.com/tracingplane/tracingplane-go/tracingplane"
"testing"
"github.com/tracingplane/tracingplane-go/atomlayer"
"fmt"
)
func
TestZipkin
(
t
*
testing
.
T
)
{
var
baggage
tracingplane
.
BaggageContext
baggage
.
Atoms
=
[]
atomlayer
.
Atom
{
{
248
,
2
},
{
240
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
55
},
{
240
,
1
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
70
},
{
240
,
2
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
10
},
}
zmd
:=
ZipkinMetadata
{}
err
:=
baggage
.
ReadBag
(
2
,
&
zmd
)
assert
.
Nil
(
t
,
err
)
assert
.
Empty
(
t
,
zmd
.
unknown
)
assert
.
False
(
t
,
zmd
.
overflowed
)
assert
.
NotNil
(
t
,
zmd
.
traceID
)
assert
.
Equal
(
t
,
int64
(
55
),
*
zmd
.
traceID
)
assert
.
NotNil
(
t
,
zmd
.
spanID
)
assert
.
Equal
(
t
,
int64
(
70
),
*
zmd
.
spanID
)
assert
.
NotNil
(
t
,
zmd
.
parentSpanID
)
assert
.
Equal
(
t
,
int64
(
10
),
*
zmd
.
parentSpanID
)
var
baggage2
tracingplane
.
BaggageContext
baggage2
.
Set
(
2
,
&
zmd
)
assert
.
Equal
(
t
,
baggage
.
Atoms
,
baggage2
.
Atoms
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment