opentelemetry-hook-sampler
Custom function based sampler for opentelemetry-python.
How to install
$ pip install opentelemetry-hook-sampler
How to use
import opentelemetry.trace
from opentelemetry.sdk.resources import SERVICE_NAME
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry_hook_sampler import HookSampler
def sampler_hook():
"""
Sample 1 in 10 traces.
The example is static, but you can get info from any context available
in your application. E.g. http request, celery task, thread locals, etc.
"""
return 10
resource = Resource(attributes={SERVICE_NAME: "foo"})
sampler = HookSampler(sampler_hook)
provider = TracerProvider(resource=resource, sampler=sampler)
opentelemetry.trace.set_tracer_provider(provider)
Honeycomb specific
Honeycomb expects a
SampleRate attribute to normalize data. It is not OpenTelemetry spec, but
it is supported through opentelemetry_hook_sampler.HoneycombHookSampler.
Sampler examples
django-threadlocals
Be careful, threadlocals module don't work with async Django.
from threadlocals.threadlocals import get_current_request
def sampler_hook():
request = get_current_request()
# 10% /foo requests
if request.path == '/foo':
return 10
return 1
django-g
from django_g import get_current_request
def sampler_hook():
request = get_current_request()
# 10% /foo requests
if request.path == '/foo':
return 10
return 1
celery
import celery
def sampler_hook():
task_name = celery.current_app.current_worker_task.request.task
# 10% foo.bar.baz tasks
if task_name == 'foo.bar.baz':
return 10
return 1
Metadata
Release files for opentelemetry-hook-sampler 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opentelemetry-hook-sampler-0.0.3.tar.gz | 4.8 kB | Without provenance | Details for opentelemetry-hook-sampler-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opentelemetry_hook_sampler-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for opentelemetry_hook_sampler-0.0.3-py3-none-any.whl |
Total release size: 10.7 kB
Release files / opentelemetry-hook-sampler-0.0.3.tar.gz
| Download URL | opentelemetry-hook-sampler-0.0.3.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09838a55fc8fa881007a69c48331ffd011cf96707878fb2c39af5bac1c7f5ab9
|
|
BLAKE2b-256 checksum How to use checksums |
bcba7f35b4e625b5ba9835cdadb2b952dd08243fc55391f49cc1c23166752487
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Release files / opentelemetry_hook_sampler-0.0.3-py3-none-any.whl
| Download URL | opentelemetry_hook_sampler-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eaa7e0d9fa1df3b0be231afea974e5b94f8bbb7c44913a2ab83aaa295c520940
|
|
BLAKE2b-256 checksum How to use checksums |
4a4b12da2372be7c6ab775a7f5e1ac50ecc6e53af7c729a1c3e35dc6a98070b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Security for opentelemetry-hook-sampler 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.