|
64 | 64 | ...
|
65 | 65 |
|
66 | 66 | The tracer sampler can also be configured via environment variables ``OTEL_TRACES_SAMPLER`` and ``OTEL_TRACES_SAMPLER_ARG`` (only if applicable).
|
67 |
| -The list of built-in values for ``OTEL_TRACES_SAMPLER`` are: |
| 67 | +The list of known values for ``OTEL_TRACES_SAMPLER`` are: |
68 | 68 |
|
69 | 69 | * always_on - Sampler that always samples spans, regardless of the parent span's sampling decision.
|
70 | 70 | * always_off - Sampler that never samples spans, regardless of the parent span's sampling decision.
|
|
73 | 73 | * parentbased_always_off - Sampler that respects its parent span's sampling decision, but otherwise never samples.
|
74 | 74 | * parentbased_traceidratio - Sampler that respects its parent span's sampling decision, but otherwise samples probabalistically based on rate.
|
75 | 75 |
|
76 |
| -Sampling probability can be set with ``OTEL_TRACES_SAMPLER_ARG`` if the sampler is traceidratio or parentbased_traceidratio. Rate must be in the range [0.0,1.0]. When not provided rate will be set to 1.0 (maximum rate possible). |
| 76 | +Sampling probability can be set with ``OTEL_TRACES_SAMPLER_ARG`` if the sampler is traceidratio or parentbased_traceidratio, when not provided rate will be set to 1.0 (maximum rate possible). |
77 | 77 |
|
78 | 78 | Prev example but with environment variables. Please make sure to set the env ``OTEL_TRACES_SAMPLER=traceidratio`` and ``OTEL_TRACES_SAMPLER_ARG=0.001``.
|
79 | 79 |
|
|
96 | 96 | # created spans will now be sampled by the TraceIdRatioBased sampler with rate 1/1000.
|
97 | 97 | with trace.get_tracer(__name__).start_as_current_span("Test Span"):
|
98 | 98 | ...
|
99 |
| -
|
100 |
| -In order to create a configurable custom sampler, create an entry point for the custom sampler factory method under the entry point group, ``opentelemetry_traces_sampler``. The custom sampler factory |
101 |
| -method must be of type ``Callable[[str], Sampler]``, taking a single string argument and returning a Sampler object. The single input will come from the string value of the |
102 |
| -``OTEL_TRACES_SAMPLER_ARG`` environment variable. If ``OTEL_TRACES_SAMPLER_ARG`` is not configured, the input will be an empty string. For example: |
103 |
| -
|
104 |
| -.. code:: python |
105 |
| -
|
106 |
| - setup( |
107 |
| - ... |
108 |
| - entry_points={ |
109 |
| - ... |
110 |
| - "opentelemetry_traces_sampler": [ |
111 |
| - "custom_sampler_name = path.to.sampler.factory.method:CustomSamplerFactory.get_sampler" |
112 |
| - ] |
113 |
| - } |
114 |
| - ) |
115 |
| - # ... |
116 |
| - class CustomRatioSampler(Sampler): |
117 |
| - def __init__(rate): |
118 |
| - # ... |
119 |
| - # ... |
120 |
| - class CustomSamplerFactory: |
121 |
| - @staticmethod |
122 |
| - get_sampler(sampler_argument): |
123 |
| - try: |
124 |
| - rate = float(sampler_argument) |
125 |
| - return CustomSampler(rate) |
126 |
| - except ValueError: # In case argument is empty string. |
127 |
| - return CustomSampler(0.5) |
128 |
| -
|
129 |
| -In order to configure you application with a custom sampler's entry point, set the ``OTEL_TRACES_SAMPLER`` environment variable to the key name of the entry point. For example, to configured the |
130 |
| -above sampler, set ``OTEL_TRACES_SAMPLER=custom_sampler_name`` and ``OTEL_TRACES_SAMPLER_ARG=0.5``. |
131 | 99 | """
|
132 | 100 | import abc
|
133 | 101 | import enum
|
|
0 commit comments