Metadata-Version: 2.5
Name: conviva-agent-traces-connector
Version: 1.2.0
Summary: OpenTelemetry helper that copies allowlisted W3C baggage entries onto every span and ensures the baggage propagator is registered.
Author: Conviva Inc.
License: Apache-2.0
Keywords: baggage,conviva,observability,opentelemetry,otel,tracing
Classifier: Framework :: OpenTelemetry
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.9
Requires-Dist: opentelemetry-api>=1.20.0
Requires-Dist: opentelemetry-sdk>=1.20.0
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Description-Content-Type: text/markdown

# conviva-agent-traces-connector

An OpenTelemetry helper library that propagates selected **W3C baggage** entries
onto your spans, so context like `c3.client_id`, `c3.conv_id`, and `c3.msg_id`
flows through your traces automatically.

> **Using `conviva-agent-tracing`?** The connector is already a dependency of
> it, and `init()` installs it. This package is for applications that run their
> own OpenTelemetry setup.

## What it does

1. **Extracts** W3C baggage entries whose key matches an allowlist (default:
   any key starting with `c3.`) from the active OpenTelemetry context.
2. **Copies** those baggage entries as attributes onto **every** span the
   process starts, via a custom `SpanProcessor.on_start`.
3. **Ensures** the global propagator includes the W3C Baggage propagator (and
   trace-context propagator) so incoming `baggage:` headers are parsed and
   outgoing HTTP calls re-inject baggage.

## Non-goals

This package deliberately does **not**:

- **Auto-instrument HTTP.** It only guarantees the baggage propagator is
  registered. Your app must install its own OTel HTTP server/client
  instrumentation (e.g. `opentelemetry-instrumentation-requests`,
  `opentelemetry-instrumentation-fastapi`) for baggage to be extracted from
  incoming requests and injected into outgoing requests at the transport layer.
- **Redact values.** Baggage values are copied verbatim (as strings).
- **Replace an existing `TracerProvider`.** It only attaches a span processor to
  the provider you already have and merges propagators.

## Install

```bash
pip install -e .
```

For development (tests):

```bash
pip install -e ".[dev]"
```

## Quickstart

```python
from conviva_agent_traces_connector import install

install()  # attaches to the global TracerProvider
```

`install()` is idempotent — calling it multiple times against the same provider
attaches the span processor only once and returns the existing processor.

You can also pass an explicit provider and/or config:

```python
from opentelemetry.sdk.trace import TracerProvider
from conviva_agent_traces_connector import Config, install

provider = TracerProvider()
install(provider, Config(attribute_prefix="conviva."))
```

## Configuration

`Config` is a frozen dataclass with the following fields:

| Field              | Type                       | Default    | Description                                                                                                      |
| ------------------ | -------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------- |
| `allowlist`        | `tuple[str, ...]`          | `("c3.",)` | A key matches if it **equals** an entry, or **starts with** an entry that ends in `.`.                          |
| `attribute_prefix` | `str`                      | `""`       | Prefix prepended to each copied attribute key (e.g. `"conviva."` turns `c3.client_id` into `conviva.c3.client_id`). |
| `logger`           | `logging.Logger \| None`   | `None`     | Optional logger used for warnings (the processor never raises from `on_start`).                                 |

Matching examples with the default allowlist `("c3.",)`:

- `c3.client_id` → matched (prefix)
- `c3.` → matched (prefix)
- `c3client_id` → not matched
- `foo` → not matched

## Public API

```python
from conviva_agent_traces_connector import (
    install,
    BaggageSpanProcessor,
    Config,
    DEFAULT_CONFIG,
    ensure_baggage_propagator,
)
```

## Development

```bash
python3 -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
pytest -q
```

## Documentation

| | |
|---|---|
| [README.md](README.md) | What the package does and its API. |
| [INTEGRATION.md](INTEGRATION.md) | Step-by-step integration into an application. |
| [AGENTS.md](AGENTS.md) | Guidance for AI coding agents working on or with this package. |
