Skip to content

Commit

Permalink
working example of tail_sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
themarcelor committed Jun 22, 2024
1 parent e7472f8 commit fbb8b92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 18 additions & 1 deletion collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ processors:
- action: insert
key: loki.resource.labels
value: service_name, deployment_environment
tail_sampling:
decision_wait: 10s
num_traces: 100
expected_new_traces_per_sec: 10
policies:
[
{
name: errors-policy,
type: status_code,
status_code: { status_codes: [ERROR] }
},
{
name: randomized-policy,
type: probabilistic,
probabilistic: { sampling_percentage: 25 },
},
]

service:
pipelines:
Expand All @@ -49,5 +66,5 @@ service:
exporters: [loki]
traces:
receivers: [otlp/traces]
processors: [resource]
processors: [resource,tail_sampling]
exporters: [otlp/traces]
8 changes: 3 additions & 5 deletions emissor-de-metricas-simples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ var meuContador otel_metric.Int64Counter

var tracer trace.Tracer

type IgnoreCaminhoSampler struct {
sampler sdktrace.Sampler
}
type IgnoreCaminhoSampler struct{}

func (ics *IgnoreCaminhoSampler) ShouldSample(p sdktrace.SamplingParameters) sdktrace.SamplingResult {
result := sdktrace.SamplingResult{
Tracestate: trace.SpanContextFromContext(p.ParentContext).TraceState(),
}
shouldSample := true
fmt.Println("### SHOULD SAMPLE EXECUTANDO!!!")
for _, att := range p.Attributes {
if att.Key == "http.target" && att.Value.AsString() == "/meh" {
shouldSample = false
Expand Down Expand Up @@ -120,8 +119,7 @@ func main() {
//}
//bsp := sdktrace.NewBatchSpanProcessor(exp)
bsp := sdktrace.NewBatchSpanProcessor(t)
s := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(0.1))
ignoreCaminhoSampler := &IgnoreCaminhoSampler{sampler: s}
ignoreCaminhoSampler := new(IgnoreCaminhoSampler)
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(ignoreCaminhoSampler),
sdktrace.WithResource(res),
Expand Down

0 comments on commit fbb8b92

Please sign in to comment.