-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
extractor_legacy.go
46 lines (40 loc) · 1.78 KB
/
extractor_legacy.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
// 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-2020 Datadog, Inc.
package event
import (
"strings"
"github.com/DataDog/datadog-agent/pkg/trace/pb"
"github.com/DataDog/datadog-agent/pkg/trace/sampler"
"github.com/DataDog/datadog-agent/pkg/trace/traceutil"
)
// legacyExtractor is an event extractor that decides whether to extract APM events from spans based on
// `serviceName => sampling rate` mappings.
type legacyExtractor struct {
rateByService map[string]float64
}
// NewLegacyExtractor returns an APM event extractor that decides whether to extract APM events from spans following the
// specified extraction rates for a span's service.
func NewLegacyExtractor(rateByService map[string]float64) Extractor {
// lower-case keys for case insensitive matching (see #3113)
rbs := make(map[string]float64, len(rateByService))
for k, v := range rateByService {
rbs[strings.ToLower(k)] = v
}
return &legacyExtractor{rateByService: rbs}
}
// Extract decides to extract an apm event from the provided span if there's an extraction rate configured for that
// span's service. In this case the extracted event is returned along with the found extraction rate and a true value.
// If this rate doesn't exist or the provided span is not a top level one, then no extraction is done and false is
// returned as the third value, with the others being invalid.
func (e *legacyExtractor) Extract(s *pb.Span, priority sampler.SamplingPriority) (float64, bool) {
if !traceutil.HasTopLevel(s) {
return 0, false
}
extractionRate, ok := e.rateByService[strings.ToLower(s.Service)]
if !ok {
return 0, false
}
return extractionRate, true
}