btx-otel 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- btx_otel-0.0.1/.gitignore +9 -0
- btx_otel-0.0.1/AGENTS.md +147 -0
- btx_otel-0.0.1/CHANGELOG.md +28 -0
- btx_otel-0.0.1/PKG-INFO +249 -0
- btx_otel-0.0.1/README.md +224 -0
- btx_otel-0.0.1/examples/first_trace.py +48 -0
- btx_otel-0.0.1/pyproject.toml +40 -0
- btx_otel-0.0.1/qa/audit.py +96 -0
- btx_otel-0.0.1/qa/benchmark.py +108 -0
- btx_otel-0.0.1/qa/hosted_mithril.py +210 -0
- btx_otel-0.0.1/qa/linux_matrix.py +104 -0
- btx_otel-0.0.1/qa/load.py +183 -0
- btx_otel-0.0.1/qa/release.py +147 -0
- btx_otel-0.0.1/qa/run.py +439 -0
- btx_otel-0.0.1/qa/test_audit.py +113 -0
- btx_otel-0.0.1/qa/test_release.py +189 -0
- btx_otel-0.0.1/qa/test_run.py +208 -0
- btx_otel-0.0.1/src/btx_otel/__init__.py +5 -0
- btx_otel-0.0.1/src/btx_otel/_policy.py +129 -0
- btx_otel-0.0.1/src/btx_otel/_processor.py +457 -0
- btx_otel-0.0.1/src/btx_otel/_response.py +61 -0
- btx_otel-0.0.1/src/btx_otel/py.typed +0 -0
- btx_otel-0.0.1/tests/application_consumer.py +91 -0
- btx_otel-0.0.1/tests/conftest.py +91 -0
- btx_otel-0.0.1/tests/fork_consumer.py +31 -0
- btx_otel-0.0.1/tests/oversized_consumer.py +80 -0
- btx_otel-0.0.1/tests/receiver_consumer.py +28 -0
- btx_otel-0.0.1/tests/test_first_trace.py +97 -0
- btx_otel-0.0.1/tests/test_lifecycle.py +231 -0
- btx_otel-0.0.1/tests/test_oversized_span.py +54 -0
- btx_otel-0.0.1/tests/test_policy.py +433 -0
- btx_otel-0.0.1/tests/test_processor.py +385 -0
- btx_otel-0.0.1/tests/test_response.py +200 -0
- btx_otel-0.0.1/tests/test_transport.py +61 -0
btx_otel-0.0.1/AGENTS.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Python OpenTelemetry package
|
|
2
|
+
|
|
3
|
+
Read this file when changing this package or its QA runner. Update the scope,
|
|
4
|
+
ownership, tier guidance, and contributor commands when their behavior changes.
|
|
5
|
+
|
|
6
|
+
## Scope and ownership
|
|
7
|
+
|
|
8
|
+
- Keep this package export-only, with `BtxSpanProcessor` as its public export
|
|
9
|
+
primitive. BTX owns export selection, bounded batching, transport,
|
|
10
|
+
and delivery diagnostics; the official OTel exporter owns bounded HTTP retries.
|
|
11
|
+
- Export masking remains private: `_SpanPatch` and the `_mask_span` hook are
|
|
12
|
+
implementation details, exercised only by internal tests and QA. Do not expose
|
|
13
|
+
them in package exports, public examples, the README, or web docs. The public
|
|
14
|
+
package exports only `BtxSpanProcessor` and `BtxExportObservation`. Publishing
|
|
15
|
+
a masking API requires a separately scoped request.
|
|
16
|
+
- The host owns span creation, instrumentation, the `TracerProvider`, sampling,
|
|
17
|
+
resource/service metadata, context propagation, and provider lifecycle. Attach
|
|
18
|
+
BTX once per provider after worker forks, and preserve existing processors and
|
|
19
|
+
exporters, including Langfuse's.
|
|
20
|
+
- Span creation APIs, tracing decorators, framework instrumentation, and a
|
|
21
|
+
provider-managing `init()` API are deferred. Do not add provider creation or
|
|
22
|
+
replacement, global tracing setup, or changes to host sampling to the SDK.
|
|
23
|
+
- Prepare for possible tracing features by keeping export independent of span
|
|
24
|
+
creation and preserving standard OTel contracts. Avoid placeholder tracing
|
|
25
|
+
APIs or scaffolding; future tracing work requires a separately scoped request.
|
|
26
|
+
|
|
27
|
+
## QA
|
|
28
|
+
|
|
29
|
+
Use `pnpm --dir code qa:otel-python -- --tier <tier>` from the repository root.
|
|
30
|
+
The default tier is `fast`; add `--plan` to inspect selection without running checks.
|
|
31
|
+
|
|
32
|
+
Choose local checks from the actual diff. Documentation, workflow, and QA-tooling
|
|
33
|
+
edits do not require SDK runtime tiers or the full soak by default:
|
|
34
|
+
|
|
35
|
+
- Docs and instructions only: run `pnpm --dir code docs:validate` and
|
|
36
|
+
`git diff --check`; verify changed links and commands.
|
|
37
|
+
- Workflow edits: run `actionlint` on the changed workflows,
|
|
38
|
+
`pnpm --dir code validate:tooling`, and the affected workflow regressions.
|
|
39
|
+
For publishing, use `node --test code/scripts/python-otel-publish.test.mjs`.
|
|
40
|
+
- QA or release-tooling edits: run the affected Python tooling tests and static
|
|
41
|
+
checks. The tooling suites can run with
|
|
42
|
+
`python3 -m unittest discover -s code/packages/btx-otel-python/qa -p 'test_*.py' -q`.
|
|
43
|
+
Use Python 3.11+ for release-tooling tests. For build or artifact changes, also
|
|
44
|
+
build/install the affected distributions and run `twine check --strict`.
|
|
45
|
+
Use a shortened soak only when needed to verify load-runner behavior.
|
|
46
|
+
|
|
47
|
+
For SDK runtime edits, select the relevant tier:
|
|
48
|
+
|
|
49
|
+
- **Fast:** Run while editing. Builds the wheel from the source distribution,
|
|
50
|
+
installs it in an isolated environment, and runs dependency/import checks,
|
|
51
|
+
a strict `pip-audit` of its installed runtime dependency closure, runner tests,
|
|
52
|
+
Ruff, mypy, and package tests, including ASGI lifecycle, transport, and an
|
|
53
|
+
isolated oversized-span stress test.
|
|
54
|
+
- **Integration:** Run before committing SDK runtime changes. Includes Fast and the real Node
|
|
55
|
+
receiver/storage tests with the installed wheel, including acknowledgement loss
|
|
56
|
+
and replay deduplication.
|
|
57
|
+
- **Release:** Run the full 600-second soak only for a release candidate or
|
|
58
|
+
runtime changes that can affect sustained delivery or resource use, such as
|
|
59
|
+
queueing, batching, retries, transport, shutdown, performance, or OTel/transport
|
|
60
|
+
dependency upgrades. Includes Integration, the Linux
|
|
61
|
+
Python 3.10–3.14 matrix, the ASGI benchmark, and a 10-minute delivery/outage/
|
|
62
|
+
recovery soak. Keep measurements sequential and avoid competing load.
|
|
63
|
+
|
|
64
|
+
Focused local checks do not replace the full Release evidence required to
|
|
65
|
+
publish the exact candidate artifacts.
|
|
66
|
+
|
|
67
|
+
Keep dependency bounds tied to passing installed-wheel cases in both the local
|
|
68
|
+
matrix and `.github/workflows/otel-python.yml`. Test the oldest supported OTel
|
|
69
|
+
version on the oldest and newest Python versions. First-export tests must verify
|
|
70
|
+
acknowledgment and matching trace IDs through local receivers, including failures.
|
|
71
|
+
|
|
72
|
+
Keep the audited dependency baseline at OTel 1.45.2, Requests 2.33.0, and urllib3 2.8.0;
|
|
73
|
+
the Python 3.10 and 3.14 consumers also test the minimum Requests version. Every QA tier
|
|
74
|
+
and compatibility CI audits the exact installed runtime dependencies, including
|
|
75
|
+
transitives, using `qa/audit.py`. It excludes the unpublished first-party wheel
|
|
76
|
+
and optional test tools, not runtime dependencies. Preserve `audit.json` and
|
|
77
|
+
`audit-requirements.txt`; a vulnerability, lookup error, missing package, or
|
|
78
|
+
skipped result fails the check. Audits require advisory-service access on each
|
|
79
|
+
run, including reused environments. Never suppress findings to obtain a pass.
|
|
80
|
+
|
|
81
|
+
User-approved temporary compatibility: allow OTel 1.45.1 for Nirva's existing
|
|
82
|
+
Python 3.13 / Langfuse 5.0.4 stack. Remove this exception once Nirva's lockfile
|
|
83
|
+
uses OTel 1.45.2 or later. OTel 1.45.0 stays excluded. The separate CI job and
|
|
84
|
+
`qa/linux_matrix.py --nirva-compat` test functional compatibility only; reports
|
|
85
|
+
label that coverage explicitly. Keep the default audited matrix and every
|
|
86
|
+
`qa/run.py` audit strict. A 1.45.1 audit is expected to fail its known advisory;
|
|
87
|
+
never treat the compatibility result as passing security or full Release QA.
|
|
88
|
+
|
|
89
|
+
The oversized-span test contains subprocess time/RSS guards and checks rejection,
|
|
90
|
+
queue release, resource regression budgets, and healthy export after bursts up
|
|
91
|
+
to 8 MiB per span. These are test workloads, not hard process-memory guarantees.
|
|
92
|
+
The queue holds unmasked data, and size calculation happens before admission.
|
|
93
|
+
Keep these privacy and capture-limit boundaries explicit in public examples.
|
|
94
|
+
|
|
95
|
+
For iteration, add `--soak-seconds 60` to Release; durations must be positive
|
|
96
|
+
whole seconds. The default remains 600 seconds. Shorter runs report
|
|
97
|
+
`validation_scope: shortened_release` and `soak.coverage: shortened`, even when
|
|
98
|
+
all checks pass. Use the default or longer duration for full Release evidence.
|
|
99
|
+
The duration does not enable a soak in Fast or Integration; `--plan` shows its
|
|
100
|
+
selection and configured duration.
|
|
101
|
+
|
|
102
|
+
Test the installed wheel; do not use an editable install or `PYTHONPATH=src` as
|
|
103
|
+
release evidence. Set `BTX_OTEL_PYTHON` to select the bootstrap interpreter.
|
|
104
|
+
The runner manages its own environment and rebuilds the wheel on every run.
|
|
105
|
+
|
|
106
|
+
Read `qa-artifacts/latest.json` and the linked check logs. A required **blocked**
|
|
107
|
+
check makes the command fail; report the prerequisite instead of calling it a
|
|
108
|
+
pass. Fix failures and rerun the affected tier. Reports and environments are
|
|
109
|
+
ignored; keep them out of commits. Do not weaken budgets to obtain a pass.
|
|
110
|
+
|
|
111
|
+
Hosted validation is separate: add `--hosted` only when the task authorizes it.
|
|
112
|
+
Use Doppler `btx/prd` and the fixed Mithril Wearables demo destination; preserve
|
|
113
|
+
temporary-key revocation on every exit. This writes synthetic spans. Verify the
|
|
114
|
+
reported trace through the project-authorized reader and viewer separately;
|
|
115
|
+
ingestion acceptance alone does not establish visibility. Never use another
|
|
116
|
+
project or persist credentials in reports.
|
|
117
|
+
|
|
118
|
+
See [contributor setup and prerequisites](../../README.md#python-opentelemetry-package).
|
|
119
|
+
Keep the public API contract in this package's `README.md`; keep QA setup in the
|
|
120
|
+
contributor guide. Keep changes local unless publication is explicitly requested.
|
|
121
|
+
|
|
122
|
+
## Publishing
|
|
123
|
+
|
|
124
|
+
- Before the first release tag, replace unpublished notices in the package
|
|
125
|
+
README with installation instructions; PyPI uses that file as its description.
|
|
126
|
+
Update public web availability notices after publication and fresh-install
|
|
127
|
+
verification succeed.
|
|
128
|
+
- `.github/workflows/publish-otel-python.yml` runs on `btx-otel-python-v<version>`
|
|
129
|
+
tags. The tag must match `pyproject.toml`, identify the clean checkout, and
|
|
130
|
+
belong to `origin/main`. Keep source validation before executing package QA.
|
|
131
|
+
- Publish only the exact wheel and source distribution from completed full
|
|
132
|
+
Release QA. Preserve both artifact hashes and reject shortened, failed,
|
|
133
|
+
incomplete, stale, or modified evidence. Do not rebuild after validation.
|
|
134
|
+
- The upload job alone gets `id-token: write`; it uses PyPI Trusted Publishing
|
|
135
|
+
and the `pypi-btx-otel` GitHub environment. Keep package builds and repository
|
|
136
|
+
code execution outside that job. Configure required environment reviewers and
|
|
137
|
+
the PyPI publisher before the first authorized release; setup is in the
|
|
138
|
+
contributor guide. Never add a PyPI token to the workflow.
|
|
139
|
+
- Keep Twine and the publishing action compatible with the build backend's core
|
|
140
|
+
metadata. Current builds emit metadata 2.5, which requires Twine 7 or later.
|
|
141
|
+
Validate both distributions with `twine check --strict` before upload.
|
|
142
|
+
- `qa/release.py` is release tooling for Python 3.11+; the workflow uses 3.14.
|
|
143
|
+
Its tests run with the QA runner tests. This does not change the SDK's supported
|
|
144
|
+
Python versions. Local validation stages files only; pushing a release tag or
|
|
145
|
+
publishing still requires an explicit request.
|
|
146
|
+
Git source checks run on the host and compatibility CI, where Git is available;
|
|
147
|
+
the slim Linux consumer matrix tests the installed SDK and QA runner.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.1 — Unreleased
|
|
4
|
+
|
|
5
|
+
- Require patched HTTP dependencies and audit installed runtime dependencies in
|
|
6
|
+
every QA tier and compatibility CI.
|
|
7
|
+
- Stress oversized-span rejection and recovery in an isolated process; clarify
|
|
8
|
+
in-memory data and host capture limits.
|
|
9
|
+
- Add `BtxSpanProcessor` for existing Python OpenTelemetry providers.
|
|
10
|
+
- Add bounded OTLP HTTP export, lifecycle methods, and metadata-only diagnostics.
|
|
11
|
+
- Preserve host sampling and existing exporter destinations.
|
|
12
|
+
- Add optional `should_export_span` selection for BTX export.
|
|
13
|
+
- Bound queued spans separately from exported spans and HTTP batches.
|
|
14
|
+
- Drop spans with sanitized diagnostics when an export policy fails.
|
|
15
|
+
- Bound HTTP responses before buffering and after gzip decompression; close and
|
|
16
|
+
reject oversized responses without retrying their batches.
|
|
17
|
+
- Report warning-only acknowledgments without exposing server text.
|
|
18
|
+
- Recommend OTel 1.45.2 and temporarily accept 1.45.1 for existing hosts, with
|
|
19
|
+
separate functional compatibility coverage and an explicit security caveat.
|
|
20
|
+
- Test installed-package compatibility with Langfuse 5.0.4 and 5.2.0.
|
|
21
|
+
- Declare the HTTP client's direct dependencies independently of OTel's transport
|
|
22
|
+
dependency choices.
|
|
23
|
+
- Verify complete acknowledgment in the first-export example, print its trace
|
|
24
|
+
ID, and fail on rejected or incomplete delivery even when the queue drains.
|
|
25
|
+
- Keep flush results scoped to each operation, including flushes overlapping shutdown.
|
|
26
|
+
- Preserve retryable connection failures when a streamed acknowledgment is truncated.
|
|
27
|
+
- Verify real application lifecycle, concurrent callers, post-fork workers, and
|
|
28
|
+
installed wheels across Python 3.10–3.14.
|
btx_otel-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: btx-otel
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Export existing OpenTelemetry traces to BTX
|
|
5
|
+
Project-URL: Documentation, https://btx.so/docs/otel/python
|
|
6
|
+
Project-URL: Source, https://github.com/dataporto/btx
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http<1.46,>=1.45.1
|
|
9
|
+
Requires-Dist: opentelemetry-sdk<1.46,>=1.45.1
|
|
10
|
+
Requires-Dist: requests<3,>=2.33.0
|
|
11
|
+
Requires-Dist: urllib3<3,>=2.8.0
|
|
12
|
+
Provides-Extra: test
|
|
13
|
+
Requires-Dist: fastapi<1,>=0.115; extra == 'test'
|
|
14
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'test'
|
|
15
|
+
Requires-Dist: langfuse<6,>=5.0.4; (python_version >= '3.11') and extra == 'test'
|
|
16
|
+
Requires-Dist: mypy<3,>=1.18; extra == 'test'
|
|
17
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi<0.67,>=0.66b0; extra == 'test'
|
|
18
|
+
Requires-Dist: pip-audit<3,>=2.10.1; extra == 'test'
|
|
19
|
+
Requires-Dist: psutil<8,>=6; extra == 'test'
|
|
20
|
+
Requires-Dist: pytest<10,>=8; extra == 'test'
|
|
21
|
+
Requires-Dist: ruff<1,>=0.14; extra == 'test'
|
|
22
|
+
Requires-Dist: types-requests<3,>=2.32; extra == 'test'
|
|
23
|
+
Requires-Dist: uvicorn<1,>=0.30; extra == 'test'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# btx-otel
|
|
27
|
+
|
|
28
|
+
Export spans from an existing Python OpenTelemetry provider to BTX.
|
|
29
|
+
This package is an export-only integration.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install btx-otel
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For setup instructions, see the [Python guide](https://btx.so/docs/otel/python).
|
|
38
|
+
|
|
39
|
+
## Scope and ownership
|
|
40
|
+
|
|
41
|
+
The host application creates spans through OpenTelemetry or existing
|
|
42
|
+
instrumentation, including Langfuse. It owns the `TracerProvider`, sampling,
|
|
43
|
+
resource and service metadata, context propagation, and application startup
|
|
44
|
+
and shutdown.
|
|
45
|
+
|
|
46
|
+
BTX attaches a `BtxSpanProcessor` to that provider. The processor owns BTX export
|
|
47
|
+
selection, bounded batching, transport, and delivery diagnostics.
|
|
48
|
+
The official OTel exporter handles bounded HTTP retries. Existing processors and
|
|
49
|
+
export destinations remain registered with the host provider.
|
|
50
|
+
|
|
51
|
+
Span creation APIs, tracing decorators, framework instrumentation, and a
|
|
52
|
+
provider-managing `init()` API are deferred to a separately scoped iteration.
|
|
53
|
+
The current integration uses `BtxSpanProcessor`; host applications continue
|
|
54
|
+
using their existing tracing APIs.
|
|
55
|
+
|
|
56
|
+
## Requirements
|
|
57
|
+
|
|
58
|
+
- Python 3.10 or later.
|
|
59
|
+
- OpenTelemetry SDK and OTLP HTTP exporter `>=1.45.1,<1.46`.
|
|
60
|
+
- Requests `>=2.33.0,<3` and urllib3 `>=2.8.0,<3`.
|
|
61
|
+
- A server-side BTX project API key.
|
|
62
|
+
|
|
63
|
+
The supported OTel range is intentionally narrow for this first version. Keep
|
|
64
|
+
your application's OTel dependencies within that range; package installation
|
|
65
|
+
must resolve one compatible SDK, including dependencies used by Langfuse.
|
|
66
|
+
Langfuse is optional. Installed-wheel compatibility tests cover OTel 1.45.2
|
|
67
|
+
across Python 3.10–3.14, including Langfuse 5.0.4 and 5.2.0 coexistence and the
|
|
68
|
+
minimum Requests version on Python 3.10 and 3.14. Core BTX export supports Python
|
|
69
|
+
3.10 independently. OTel 1.44 and
|
|
70
|
+
earlier lack the exporter's request-size option used by this package; newer
|
|
71
|
+
minor versions require validation before expanding the supported range.
|
|
72
|
+
|
|
73
|
+
Use OTel 1.45.2 or later in the 1.45 series. OTel 1.45.1 is temporarily accepted
|
|
74
|
+
for existing hosts, with separate functional compatibility coverage on Python
|
|
75
|
+
3.13 and Langfuse 5.0.4. It has a known propagation denial-of-service advisory
|
|
76
|
+
and fails the vulnerability audit. This compatibility exception does not make
|
|
77
|
+
that dependency set security-qualified. Remove the older version when the host
|
|
78
|
+
can upgrade its shared OTel dependencies. OTel 1.45.0 remains unsupported.
|
|
79
|
+
|
|
80
|
+
The HTTP dependency minimums exclude known Requests credential/temp-file issues
|
|
81
|
+
and urllib3 proxy TLS issues.
|
|
82
|
+
|
|
83
|
+
## Add BTX export
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import os
|
|
87
|
+
from btx_otel import BtxSpanProcessor
|
|
88
|
+
|
|
89
|
+
btx_processor = BtxSpanProcessor(api_key=os.environ["BTX_API_KEY"])
|
|
90
|
+
provider.add_span_processor(btx_processor)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`provider` is your application's existing `TracerProvider`. Initialize this
|
|
94
|
+
processor once per provider, after any worker forks. Keep existing processors,
|
|
95
|
+
including Langfuse's, registered. Creating, configuring, and shutting down the
|
|
96
|
+
provider remain the host application's responsibility.
|
|
97
|
+
|
|
98
|
+
## Filter spans
|
|
99
|
+
|
|
100
|
+
To skip selected spans, replace the processor construction in the setup example
|
|
101
|
+
with:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
btx_processor = BtxSpanProcessor(
|
|
105
|
+
api_key=os.environ["BTX_API_KEY"],
|
|
106
|
+
should_export_span=lambda span: span.name != "healthcheck",
|
|
107
|
+
)
|
|
108
|
+
provider.add_span_processor(btx_processor)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`should_export_span` receives an ended, sampled `ReadableSpan` on the span-ending
|
|
112
|
+
thread, before queue admission. Return `True` to export to BTX or `False` to skip
|
|
113
|
+
it. Selection applies to each span independently; excluding a parent does not
|
|
114
|
+
exclude its children or change their parent IDs. Other destinations are unchanged.
|
|
115
|
+
|
|
116
|
+
Treat the span as read-only. Keep the callback fast and thread-safe, and avoid
|
|
117
|
+
network calls and instrumented work. An exception or invalid return value drops
|
|
118
|
+
that BTX span and reports `failed` with reason `filter_failed`; exception details
|
|
119
|
+
stay out of diagnostics. Without a callback, BTX exports sampled spans.
|
|
120
|
+
|
|
121
|
+
### Control sensitive data
|
|
122
|
+
|
|
123
|
+
Sanitize data in your instrumentation before spans end. Review names, attributes,
|
|
124
|
+
exception events and stack traces, status descriptions, resources, and links.
|
|
125
|
+
Policies configured in another exporter, including Langfuse, do not sanitize
|
|
126
|
+
BTX exports. The queue retains original span data in memory until export finishes.
|
|
127
|
+
Keep the project API key server-side in your secret manager and rotate it if
|
|
128
|
+
exposed.
|
|
129
|
+
|
|
130
|
+
## Verify delivery
|
|
131
|
+
|
|
132
|
+
Run an existing instrumented request or job. After its spans finish, flush the
|
|
133
|
+
BTX processor and find the trace in BTX. With Langfuse export enabled, check the
|
|
134
|
+
same trace ID in both destinations.
|
|
135
|
+
|
|
136
|
+
The standalone [first-export example](examples/first_trace.py) uses the host
|
|
137
|
+
application's standard OTel APIs to create one root and three child spans. With
|
|
138
|
+
`BTX_API_KEY` set, it prints the trace ID and requires an `accepted` acknowledgment
|
|
139
|
+
for all four spans. Auth rejection, incomplete acknowledgment, and flush timeout
|
|
140
|
+
fail the verification instead of reporting success. Search for the printed trace
|
|
141
|
+
ID in your BTX project to verify visibility; an acknowledgment alone does not
|
|
142
|
+
establish storage or viewer visibility. The example owns and shuts down its
|
|
143
|
+
provider; an existing host app retains its own provider lifecycle.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
drained = btx_processor.force_flush(timeout_millis=20_000)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`force_flush()` returns `False` if its deadline expires. `True` means the queued
|
|
150
|
+
export attempts finished; it does not guarantee storage. A failed attempt can
|
|
151
|
+
finish draining the queue. Flush after traced work finishes and before a
|
|
152
|
+
short-lived runtime pauses. The method blocks the caller; use your framework's
|
|
153
|
+
thread offloading when calling it from async code.
|
|
154
|
+
|
|
155
|
+
During application shutdown, call `provider.shutdown()`. The BTX processor stops
|
|
156
|
+
accepting new spans and waits up to 20 seconds. Cleanup can continue in a daemon
|
|
157
|
+
thread after a timeout. Buffered data does not survive process termination.
|
|
158
|
+
|
|
159
|
+
## Observe delivery
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from btx_otel import BtxExportObservation, BtxSpanProcessor
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def observe_export(result: BtxExportObservation) -> None:
|
|
166
|
+
print(result.outcome, result.spans, result.reason)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
btx_processor = BtxSpanProcessor(
|
|
170
|
+
api_key=os.environ["BTX_API_KEY"],
|
|
171
|
+
on_export=observe_export,
|
|
172
|
+
)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Register one processor from these examples. Observations contain `outcome`,
|
|
176
|
+
`spans`, `reason`, `http_status`, and `rejected_spans`. Outcomes are `accepted`,
|
|
177
|
+
`failed`, `partial_success`, and `overflow`. The counts describe the attempted
|
|
178
|
+
batch; `rejected_spans` identifies the rejected portion of a partial acknowledgment.
|
|
179
|
+
Partial-success responses are not replayed. Failed batches are not durably queued
|
|
180
|
+
for later recovery; the official exporter owns its bounded transport retries.
|
|
181
|
+
|
|
182
|
+
A warning-only acknowledgment reports `accepted` with reason `server_warning`
|
|
183
|
+
and zero rejected spans. Server warning text is never included in diagnostics.
|
|
184
|
+
Without a callback, these warnings use the same bounded logger as failures.
|
|
185
|
+
|
|
186
|
+
`on_export` can run on the application or exporter thread. Keep it fast and avoid
|
|
187
|
+
instrumented work inside it. Exceptions raised by this callback are ignored.
|
|
188
|
+
Without a callback, failures use the `btx_otel` logger. Diagnostics contain no
|
|
189
|
+
credentials, response bodies, or span content.
|
|
190
|
+
Repeated warnings for the same failure reason are suppressed until an export succeeds.
|
|
191
|
+
|
|
192
|
+
## Advanced: Configure delivery
|
|
193
|
+
|
|
194
|
+
Delivery tuning is optional. Start with the defaults and override only the
|
|
195
|
+
settings your workload needs. For example, to shorten the export interval from
|
|
196
|
+
30 seconds to 5 seconds, replace the basic processor configuration:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
btx_processor = BtxSpanProcessor(
|
|
200
|
+
api_key=os.environ["BTX_API_KEY"],
|
|
201
|
+
schedule_delay_millis=5_000,
|
|
202
|
+
)
|
|
203
|
+
provider.add_span_processor(btx_processor)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Register only one BTX processor. The supported delivery options are:
|
|
207
|
+
|
|
208
|
+
| Option | Default |
|
|
209
|
+
| --- | --- |
|
|
210
|
+
| `max_queue_size` | 512 pending spans, including export in progress |
|
|
211
|
+
| `max_export_batch_size` | 128 spans |
|
|
212
|
+
| `schedule_delay_millis` | 30,000 ms |
|
|
213
|
+
| `export_timeout_millis` | 15,000 ms per HTTP export |
|
|
214
|
+
|
|
215
|
+
Values must be positive integers, and `max_export_batch_size` must not exceed
|
|
216
|
+
`max_queue_size`. The export timeout applies to the HTTP exporter. The
|
|
217
|
+
`force_flush(timeout_millis=...)` deadline separately bounds the caller's wait.
|
|
218
|
+
|
|
219
|
+
The queue holds original spans within a 4 MiB encoded-size budget, including
|
|
220
|
+
export in progress. Size calculation runs synchronously when a span ends. A span
|
|
221
|
+
that exceeds the remaining queue budget is dropped.
|
|
222
|
+
|
|
223
|
+
The queue budget is not a total process-memory limit. Calculating encoded size
|
|
224
|
+
allocates a temporary representation before admission, and hooks can allocate
|
|
225
|
+
additional memory. Limit captured string lengths, attribute counts, events, and
|
|
226
|
+
links in the host's instrumentation and OTel span limits. Do not capture entire
|
|
227
|
+
request bodies or unbounded model output and rely on the queue to make it safe.
|
|
228
|
+
|
|
229
|
+
A single exported span must fit 128 KiB, and export batches split into requests
|
|
230
|
+
within a separate 4 MiB budget. Overhead is counted conservatively for each span.
|
|
231
|
+
Overflow drops the affected span and emits a diagnostic. Queue accounting is
|
|
232
|
+
released after all HTTP attempts for its batch finish. The receiver separately
|
|
233
|
+
enforces its projected JSON size limit; a span can fit its Protobuf budget and
|
|
234
|
+
still be rejected by the receiver. Accepted span content is not rewritten or
|
|
235
|
+
truncated.
|
|
236
|
+
|
|
237
|
+
HTTP response bodies have separate 4 MiB wire and decompressed limits. BTX reads
|
|
238
|
+
them incrementally and supports identity and gzip encoding. An oversized response
|
|
239
|
+
stops reading, closes the connection, and reports `failed` with reason
|
|
240
|
+
`response_too_large`; the batch is not retried. Invalid or unsupported response
|
|
241
|
+
encoding and malformed acknowledgments report `invalid_acknowledgment` without
|
|
242
|
+
retrying. These failures do not establish whether the server stored the batch.
|
|
243
|
+
|
|
244
|
+
BTX uses OTLP HTTP Protobuf and owns the endpoint and authorization headers.
|
|
245
|
+
Global OTel endpoint, header, and compression settings do not redirect BTX
|
|
246
|
+
exports. Trace IDs, parent relationships, resource/scope metadata, attributes,
|
|
247
|
+
events, links, and host sampling remain with the application.
|
|
248
|
+
|
|
249
|
+
See [connection details and troubleshooting](https://btx.so/docs/otel).
|
btx_otel-0.0.1/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# btx-otel
|
|
2
|
+
|
|
3
|
+
Export spans from an existing Python OpenTelemetry provider to BTX.
|
|
4
|
+
This package is an export-only integration.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install btx-otel
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
For setup instructions, see the [Python guide](https://btx.so/docs/otel/python).
|
|
13
|
+
|
|
14
|
+
## Scope and ownership
|
|
15
|
+
|
|
16
|
+
The host application creates spans through OpenTelemetry or existing
|
|
17
|
+
instrumentation, including Langfuse. It owns the `TracerProvider`, sampling,
|
|
18
|
+
resource and service metadata, context propagation, and application startup
|
|
19
|
+
and shutdown.
|
|
20
|
+
|
|
21
|
+
BTX attaches a `BtxSpanProcessor` to that provider. The processor owns BTX export
|
|
22
|
+
selection, bounded batching, transport, and delivery diagnostics.
|
|
23
|
+
The official OTel exporter handles bounded HTTP retries. Existing processors and
|
|
24
|
+
export destinations remain registered with the host provider.
|
|
25
|
+
|
|
26
|
+
Span creation APIs, tracing decorators, framework instrumentation, and a
|
|
27
|
+
provider-managing `init()` API are deferred to a separately scoped iteration.
|
|
28
|
+
The current integration uses `BtxSpanProcessor`; host applications continue
|
|
29
|
+
using their existing tracing APIs.
|
|
30
|
+
|
|
31
|
+
## Requirements
|
|
32
|
+
|
|
33
|
+
- Python 3.10 or later.
|
|
34
|
+
- OpenTelemetry SDK and OTLP HTTP exporter `>=1.45.1,<1.46`.
|
|
35
|
+
- Requests `>=2.33.0,<3` and urllib3 `>=2.8.0,<3`.
|
|
36
|
+
- A server-side BTX project API key.
|
|
37
|
+
|
|
38
|
+
The supported OTel range is intentionally narrow for this first version. Keep
|
|
39
|
+
your application's OTel dependencies within that range; package installation
|
|
40
|
+
must resolve one compatible SDK, including dependencies used by Langfuse.
|
|
41
|
+
Langfuse is optional. Installed-wheel compatibility tests cover OTel 1.45.2
|
|
42
|
+
across Python 3.10–3.14, including Langfuse 5.0.4 and 5.2.0 coexistence and the
|
|
43
|
+
minimum Requests version on Python 3.10 and 3.14. Core BTX export supports Python
|
|
44
|
+
3.10 independently. OTel 1.44 and
|
|
45
|
+
earlier lack the exporter's request-size option used by this package; newer
|
|
46
|
+
minor versions require validation before expanding the supported range.
|
|
47
|
+
|
|
48
|
+
Use OTel 1.45.2 or later in the 1.45 series. OTel 1.45.1 is temporarily accepted
|
|
49
|
+
for existing hosts, with separate functional compatibility coverage on Python
|
|
50
|
+
3.13 and Langfuse 5.0.4. It has a known propagation denial-of-service advisory
|
|
51
|
+
and fails the vulnerability audit. This compatibility exception does not make
|
|
52
|
+
that dependency set security-qualified. Remove the older version when the host
|
|
53
|
+
can upgrade its shared OTel dependencies. OTel 1.45.0 remains unsupported.
|
|
54
|
+
|
|
55
|
+
The HTTP dependency minimums exclude known Requests credential/temp-file issues
|
|
56
|
+
and urllib3 proxy TLS issues.
|
|
57
|
+
|
|
58
|
+
## Add BTX export
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import os
|
|
62
|
+
from btx_otel import BtxSpanProcessor
|
|
63
|
+
|
|
64
|
+
btx_processor = BtxSpanProcessor(api_key=os.environ["BTX_API_KEY"])
|
|
65
|
+
provider.add_span_processor(btx_processor)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`provider` is your application's existing `TracerProvider`. Initialize this
|
|
69
|
+
processor once per provider, after any worker forks. Keep existing processors,
|
|
70
|
+
including Langfuse's, registered. Creating, configuring, and shutting down the
|
|
71
|
+
provider remain the host application's responsibility.
|
|
72
|
+
|
|
73
|
+
## Filter spans
|
|
74
|
+
|
|
75
|
+
To skip selected spans, replace the processor construction in the setup example
|
|
76
|
+
with:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
btx_processor = BtxSpanProcessor(
|
|
80
|
+
api_key=os.environ["BTX_API_KEY"],
|
|
81
|
+
should_export_span=lambda span: span.name != "healthcheck",
|
|
82
|
+
)
|
|
83
|
+
provider.add_span_processor(btx_processor)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`should_export_span` receives an ended, sampled `ReadableSpan` on the span-ending
|
|
87
|
+
thread, before queue admission. Return `True` to export to BTX or `False` to skip
|
|
88
|
+
it. Selection applies to each span independently; excluding a parent does not
|
|
89
|
+
exclude its children or change their parent IDs. Other destinations are unchanged.
|
|
90
|
+
|
|
91
|
+
Treat the span as read-only. Keep the callback fast and thread-safe, and avoid
|
|
92
|
+
network calls and instrumented work. An exception or invalid return value drops
|
|
93
|
+
that BTX span and reports `failed` with reason `filter_failed`; exception details
|
|
94
|
+
stay out of diagnostics. Without a callback, BTX exports sampled spans.
|
|
95
|
+
|
|
96
|
+
### Control sensitive data
|
|
97
|
+
|
|
98
|
+
Sanitize data in your instrumentation before spans end. Review names, attributes,
|
|
99
|
+
exception events and stack traces, status descriptions, resources, and links.
|
|
100
|
+
Policies configured in another exporter, including Langfuse, do not sanitize
|
|
101
|
+
BTX exports. The queue retains original span data in memory until export finishes.
|
|
102
|
+
Keep the project API key server-side in your secret manager and rotate it if
|
|
103
|
+
exposed.
|
|
104
|
+
|
|
105
|
+
## Verify delivery
|
|
106
|
+
|
|
107
|
+
Run an existing instrumented request or job. After its spans finish, flush the
|
|
108
|
+
BTX processor and find the trace in BTX. With Langfuse export enabled, check the
|
|
109
|
+
same trace ID in both destinations.
|
|
110
|
+
|
|
111
|
+
The standalone [first-export example](examples/first_trace.py) uses the host
|
|
112
|
+
application's standard OTel APIs to create one root and three child spans. With
|
|
113
|
+
`BTX_API_KEY` set, it prints the trace ID and requires an `accepted` acknowledgment
|
|
114
|
+
for all four spans. Auth rejection, incomplete acknowledgment, and flush timeout
|
|
115
|
+
fail the verification instead of reporting success. Search for the printed trace
|
|
116
|
+
ID in your BTX project to verify visibility; an acknowledgment alone does not
|
|
117
|
+
establish storage or viewer visibility. The example owns and shuts down its
|
|
118
|
+
provider; an existing host app retains its own provider lifecycle.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
drained = btx_processor.force_flush(timeout_millis=20_000)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`force_flush()` returns `False` if its deadline expires. `True` means the queued
|
|
125
|
+
export attempts finished; it does not guarantee storage. A failed attempt can
|
|
126
|
+
finish draining the queue. Flush after traced work finishes and before a
|
|
127
|
+
short-lived runtime pauses. The method blocks the caller; use your framework's
|
|
128
|
+
thread offloading when calling it from async code.
|
|
129
|
+
|
|
130
|
+
During application shutdown, call `provider.shutdown()`. The BTX processor stops
|
|
131
|
+
accepting new spans and waits up to 20 seconds. Cleanup can continue in a daemon
|
|
132
|
+
thread after a timeout. Buffered data does not survive process termination.
|
|
133
|
+
|
|
134
|
+
## Observe delivery
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from btx_otel import BtxExportObservation, BtxSpanProcessor
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def observe_export(result: BtxExportObservation) -> None:
|
|
141
|
+
print(result.outcome, result.spans, result.reason)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
btx_processor = BtxSpanProcessor(
|
|
145
|
+
api_key=os.environ["BTX_API_KEY"],
|
|
146
|
+
on_export=observe_export,
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Register one processor from these examples. Observations contain `outcome`,
|
|
151
|
+
`spans`, `reason`, `http_status`, and `rejected_spans`. Outcomes are `accepted`,
|
|
152
|
+
`failed`, `partial_success`, and `overflow`. The counts describe the attempted
|
|
153
|
+
batch; `rejected_spans` identifies the rejected portion of a partial acknowledgment.
|
|
154
|
+
Partial-success responses are not replayed. Failed batches are not durably queued
|
|
155
|
+
for later recovery; the official exporter owns its bounded transport retries.
|
|
156
|
+
|
|
157
|
+
A warning-only acknowledgment reports `accepted` with reason `server_warning`
|
|
158
|
+
and zero rejected spans. Server warning text is never included in diagnostics.
|
|
159
|
+
Without a callback, these warnings use the same bounded logger as failures.
|
|
160
|
+
|
|
161
|
+
`on_export` can run on the application or exporter thread. Keep it fast and avoid
|
|
162
|
+
instrumented work inside it. Exceptions raised by this callback are ignored.
|
|
163
|
+
Without a callback, failures use the `btx_otel` logger. Diagnostics contain no
|
|
164
|
+
credentials, response bodies, or span content.
|
|
165
|
+
Repeated warnings for the same failure reason are suppressed until an export succeeds.
|
|
166
|
+
|
|
167
|
+
## Advanced: Configure delivery
|
|
168
|
+
|
|
169
|
+
Delivery tuning is optional. Start with the defaults and override only the
|
|
170
|
+
settings your workload needs. For example, to shorten the export interval from
|
|
171
|
+
30 seconds to 5 seconds, replace the basic processor configuration:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
btx_processor = BtxSpanProcessor(
|
|
175
|
+
api_key=os.environ["BTX_API_KEY"],
|
|
176
|
+
schedule_delay_millis=5_000,
|
|
177
|
+
)
|
|
178
|
+
provider.add_span_processor(btx_processor)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Register only one BTX processor. The supported delivery options are:
|
|
182
|
+
|
|
183
|
+
| Option | Default |
|
|
184
|
+
| --- | --- |
|
|
185
|
+
| `max_queue_size` | 512 pending spans, including export in progress |
|
|
186
|
+
| `max_export_batch_size` | 128 spans |
|
|
187
|
+
| `schedule_delay_millis` | 30,000 ms |
|
|
188
|
+
| `export_timeout_millis` | 15,000 ms per HTTP export |
|
|
189
|
+
|
|
190
|
+
Values must be positive integers, and `max_export_batch_size` must not exceed
|
|
191
|
+
`max_queue_size`. The export timeout applies to the HTTP exporter. The
|
|
192
|
+
`force_flush(timeout_millis=...)` deadline separately bounds the caller's wait.
|
|
193
|
+
|
|
194
|
+
The queue holds original spans within a 4 MiB encoded-size budget, including
|
|
195
|
+
export in progress. Size calculation runs synchronously when a span ends. A span
|
|
196
|
+
that exceeds the remaining queue budget is dropped.
|
|
197
|
+
|
|
198
|
+
The queue budget is not a total process-memory limit. Calculating encoded size
|
|
199
|
+
allocates a temporary representation before admission, and hooks can allocate
|
|
200
|
+
additional memory. Limit captured string lengths, attribute counts, events, and
|
|
201
|
+
links in the host's instrumentation and OTel span limits. Do not capture entire
|
|
202
|
+
request bodies or unbounded model output and rely on the queue to make it safe.
|
|
203
|
+
|
|
204
|
+
A single exported span must fit 128 KiB, and export batches split into requests
|
|
205
|
+
within a separate 4 MiB budget. Overhead is counted conservatively for each span.
|
|
206
|
+
Overflow drops the affected span and emits a diagnostic. Queue accounting is
|
|
207
|
+
released after all HTTP attempts for its batch finish. The receiver separately
|
|
208
|
+
enforces its projected JSON size limit; a span can fit its Protobuf budget and
|
|
209
|
+
still be rejected by the receiver. Accepted span content is not rewritten or
|
|
210
|
+
truncated.
|
|
211
|
+
|
|
212
|
+
HTTP response bodies have separate 4 MiB wire and decompressed limits. BTX reads
|
|
213
|
+
them incrementally and supports identity and gzip encoding. An oversized response
|
|
214
|
+
stops reading, closes the connection, and reports `failed` with reason
|
|
215
|
+
`response_too_large`; the batch is not retried. Invalid or unsupported response
|
|
216
|
+
encoding and malformed acknowledgments report `invalid_acknowledgment` without
|
|
217
|
+
retrying. These failures do not establish whether the server stored the batch.
|
|
218
|
+
|
|
219
|
+
BTX uses OTLP HTTP Protobuf and owns the endpoint and authorization headers.
|
|
220
|
+
Global OTel endpoint, header, and compression settings do not redirect BTX
|
|
221
|
+
exports. Trace IDs, parent relationships, resource/scope metadata, attributes,
|
|
222
|
+
events, links, and host sampling remain with the application.
|
|
223
|
+
|
|
224
|
+
See [connection details and troubleshooting](https://btx.so/docs/otel).
|