/
trace.go
52 lines (44 loc) · 1.58 KB
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package trace
//go:generate go run github.com/tinylib/msgp -file=span.pb.go -o span_gen.go -io=false
//go:generate go run github.com/tinylib/msgp -file=tracer_payload.pb.go -o tracer_payload_gen.go -io=false
//go:generate go run github.com/tinylib/msgp -io=false
// Trace is a collection of spans with the same trace ID
type Trace []*Span
// Traces is a list of traces. This model matters as this is what we unpack from msgp.
type Traces []Trace
// RemoveChunk removes a chunk by its index.
func (p *TracerPayload) RemoveChunk(i int) {
if i < 0 || i >= len(p.Chunks) {
return
}
p.Chunks[i] = p.Chunks[len(p.Chunks)-1]
p.Chunks = p.Chunks[:len(p.Chunks)-1]
}
// Cut cuts off a new tracer payload from the `p` with [0, i-1] chunks
// and keeps [i, n-1] chunks in the original payload `p`.
func (p *TracerPayload) Cut(i int) *TracerPayload {
if i < 0 {
i = 0
}
if i > len(p.Chunks) {
i = len(p.Chunks)
}
newPayload := TracerPayload{
ContainerID: p.GetContainerID(),
LanguageName: p.GetLanguageName(),
LanguageVersion: p.GetLanguageVersion(),
TracerVersion: p.GetTracerVersion(),
RuntimeID: p.GetRuntimeID(),
Env: p.GetEnv(),
Hostname: p.GetHostname(),
AppVersion: p.GetAppVersion(),
Tags: p.GetTags(),
}
newPayload.Chunks = p.Chunks[:i]
p.Chunks = p.Chunks[i:]
return &newPayload
}