@@ -8,8 +8,7 @@ spans that are generated by a system. The exact sampler you should use depends
88on your specific needs, but in general you should make a decision at the start
99of a trace, and allow the sampling decision to propagate to other services.
1010
11- A [ ` Sampler ` ] ( https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#Sampler ) can
12- be set on the tracer provider using the
11+ A [ ` Sampler ` ] [ ] can be set on the tracer provider using the
1312[ ` WithSampler ` ] ( https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#WithSampler )
1413option, as follows:
1514
@@ -46,31 +45,27 @@ the `TraceIDRatioBased` sampler.
4645## Custom samplers
4746
4847If the built-in samplers don't meet your needs, you can create a custom sampler
49- by implementing the
50- [ ` Sampler ` ] ( https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#Sampler )
51- interface. A custom sampler must implement two methods:
48+ by implementing the [ ` Sampler ` ] [ ] interface. A custom sampler must implement two
49+ methods:
5250
5351- ` ShouldSample(parameters SamplingParameters) SamplingResult ` : Makes the
5452 sampling decision based on the provided parameters.
5553- ` Description() string ` : Returns a description of the sampler.
5654
57- ### Preserving tracestate
58-
59- {{% alert title="Critical: Preserve tracestate" color="warning" %}}
60-
61- When implementing a custom sampler, you ** must** preserve the parent's
62- tracestate in your ` SamplingResult ` . Failing to do so breaks context propagation
63- in distributed systems that rely on tracestate for passing vendor-specific or
64- application-specific trace data.
65-
66- Always extract the tracestate from the parent span context:
67-
68- ``` go
69- psc := trace.SpanContextFromContext (parameters.ParentContext )
70- // Use psc.TraceState() in your SamplingResult
71- ```
72-
73- {{% /alert %}}
55+ > [ !IMPORTANT] Preserve parent tracestate
56+ >
57+ > In ` ShouldSample ` , you _ must_ preserve the parent's tracestate in your
58+ > ` SamplingResult ` . Failing to do so breaks context propagation in distributed
59+ > systems that rely on tracestate for passing vendor-specific or
60+ > application-specific trace data.
61+ >
62+ > Extract the tracestate from the parent span context:
63+ >
64+ > ``` go
65+ > psc := trace.SpanContextFromContext (parameters.ParentContext )
66+ > ` ` `
67+ >
68+ > Pass ` psc.TraceState ()` through when you build your ` SamplingResult` .
7469
7570### Example
7671
@@ -167,3 +162,5 @@ When implementing custom samplers, keep these points in mind:
1671622 . ** Heavy computations in ShouldSample** : The ` ShouldSample ` function is called
168163 synchronously for every span creation. Avoid expensive operations like
169164 network calls or complex computations that could impact performance.
165+
166+ [ `Sampler` ] : https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#Sampler
0 commit comments