Metadata-Version: 2.5
Name: confident-trace
Version: 0.1.0
Summary: OpenTelemetry-first tracing for AI applications
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: opentelemetry-api<2,>=1.39
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc<2,>=1.39
Requires-Dist: opentelemetry-exporter-otlp-proto-http<2,>=1.39
Requires-Dist: opentelemetry-sdk<2,>=1.39
Requires-Dist: wrapt<3,>=1.17
Provides-Extra: agent-sdks-test
Requires-Dist: claude-agent-sdk; extra == 'agent-sdks-test'
Requires-Dist: openai-agents; extra == 'agent-sdks-test'
Requires-Dist: openinference-instrumentation-openai-agents<3,>=2.2.1; extra == 'agent-sdks-test'
Provides-Extra: agentcore
Requires-Dist: opentelemetry-instrumentation-asgi; extra == 'agentcore'
Provides-Extra: crewai-test
Requires-Dist: crewai<2,>=1; extra == 'crewai-test'
Provides-Extra: frameworks-test
Requires-Dist: agno; extra == 'frameworks-test'
Requires-Dist: llama-index-core; extra == 'frameworks-test'
Requires-Dist: llama-index-llms-openai; extra == 'frameworks-test'
Requires-Dist: smolagents[openai]; extra == 'frameworks-test'
Provides-Extra: langchain-test
Requires-Dist: langchain-openai<2,>=1; extra == 'langchain-test'
Requires-Dist: langchain<2,>=1; extra == 'langchain-test'
Requires-Dist: langgraph<2,>=1; extra == 'langchain-test'
Provides-Extra: microsoft-test
Requires-Dist: agent-framework-core; extra == 'microsoft-test'
Requires-Dist: agent-framework-openai; extra == 'microsoft-test'
Provides-Extra: native-test
Requires-Dist: bedrock-agentcore; extra == 'native-test'
Requires-Dist: google-adk; extra == 'native-test'
Requires-Dist: opentelemetry-instrumentation-asgi; extra == 'native-test'
Requires-Dist: pydantic-ai-slim[openai]; extra == 'native-test'
Requires-Dist: strands-agents[openai,otel]; extra == 'native-test'
Provides-Extra: openai-agents
Requires-Dist: openinference-instrumentation-openai-agents<3,>=2.2.1; extra == 'openai-agents'
Provides-Extra: test
Requires-Dist: anthropic<2,>=0.69; extra == 'test'
Requires-Dist: boto3<2,>=1.40; extra == 'test'
Requires-Dist: google-genai<3,>=1.40; extra == 'test'
Requires-Dist: jsonschema<5,>=4.23; extra == 'test'
Requires-Dist: openai<4,>=1.109; extra == 'test'
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Requires-Dist: pyyaml<7,>=6; extra == 'test'
Description-Content-Type: text/markdown

# Confident Trace

OpenTelemetry-first tracing for AI workloads. No Confident wire format, local
agent, replacement provider clients, or dependency on DeepEval.

```python
from confident_trace import init
from openai import OpenAI

init()  # reads CONFIDENT_API_KEY and instruments installed supported SDKs
client = OpenAI()

response = client.responses.create(model="gpt-4.1-mini", input="Hello")
```

That call automatically emits and exports an OTel span. No decorator or manual
trace submission is required. Calls inherit the current OTel context, so calls
inside an already-instrumented agent/request join its trace. Without a parent,
a call starts its own trace. Existing framework OTel spans are exported too.

`@span` is optional: use it to add a custom step or instrument an application
entry point that does not already emit OTel spans. The current provider
instrumentors capture LLM calls and requested tools; arbitrary Python tool
execution needs a framework's OTel instrumentation or a decorator. `init()`
cannot infer request boundaries or tool execution in otherwise uninstrumented
code.

Spans sharing an OTel trace ID make up a trace. Setting
`confident.trace.thread_id` associates that trace with a conversation, where it
represents a turn. This is metadata, not a separate SDK scope or object, and does
not change span parentage or merge traces. Explicit thread IDs also populate the standard
`gen_ai.conversation.id` on the entry and subsequent package spans. See `examples/conversation.py` for
adding conversation metadata to an optional custom entry point.

Development install: `pip install -e './python[test]'` from the repository root.
Version 0.1.0 is the initial release; the API may change before 1.0.0. See the release compatibility matrix for coverage.

## What is supported?

- **Automatically instrumented SDK calls:** OpenAI, Anthropic, Google GenAI, and AWS Bedrock Runtime (Boto3).
  We wrap their supported Python methods and emit OTel spans ourselves.
- **In-house framework integration:** LangChain and LangGraph; full callback hierarchy,
  GenAI model/tool spans, and standard OTel nesting inside nodes and tools.
  CrewAI, LlamaIndex, Agno and smolagents capture execution structure with
  provider-owned inference spans; see [framework ownership](docs/frameworks.md).
- **Native framework integration:** Pydantic AI, Strands, Google ADK, Microsoft Agent
  Framework, AgentCore, OpenAI Agents (requires the tracing bridge extra), and
  Claude Agent SDK (native child-process export). See [setup and native limitations](docs/integrations.md).
- **Existing OTel spans:** we export spans an SDK/framework or external instrumentor
  already emits through the shared provider. Framework instrumentation must already
  be enabled; backend GenAI interpretation depends on its conventions.
- **Custom code:** use the optional `@span` decorator.

See the [support mechanisms and version matrix](docs/compatibility.md) for
exact methods, who emits spans, automatic setup, and tested versus unverified
coverage. Existing OTel transport support is not a claim that all agent frameworks
are automatically instrumented or fully mapped.

## Configuration

`init()` reads `CONFIDENT_API_KEY`, `OTEL_SDK_DISABLED`,
`OTEL_RESOURCE_ATTRIBUTES`, and standard OTel exporter settings. Unspecified
exporter options are delegated to OTel, including TLS certificates/client keys,
compression, headers, timeouts and HTTP endpoint path resolution.

Explicit arguments override environment settings. `OTEL_SDK_DISABLED=true`
always disables package tracing at initialization. Trace-specific exporter
settings take precedence over generic settings. An explicit `endpoint` is the
complete traces endpoint; an HTTP generic environment endpoint gets `/v1/traces`
appended by OTel. Timeouts passed to `init` are seconds; `flush` and `shutdown`
budgets are milliseconds. Explicit `headers` override environment/auth headers.

```sh
export CONFIDENT_API_KEY=...
export OTEL_RESOURCE_ATTRIBUTES='service.name=my-agent,deployment.environment.name=staging'
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4318/v1/traces
# Or a gRPC Collector:
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
# Disable in CI:
export OTEL_SDK_DISABLED=true
```

A supplied API key is forwarded to the configured endpoint. When using a
Collector that does not require it, omit the variable or pass `api_key=""`.
The Confident default endpoint supports HTTP/protobuf. gRPC requires a custom
endpoint. Authentication and project selection are handled by the backend.

`init(tracer_provider=provider)` adds only a standard batch export pipeline to
an existing SDK provider. It does not change its resources, sampler, propagator,
or other processors. Resource arguments apply only when creating a provider.
Without an explicit provider, an existing global provider is reused. Standard
OTel W3C propagation remains available; the package does not instrument HTTP
frameworks or install a different propagator.

Initialization is idempotent; call `shutdown()` before reconfiguring. Initialization
failure returns an inactive runtime and logs a content-free warning. `flush()`
reports whether the queue drained, not whether the remote backend accepted data.
`shutdown(timeout_millis=5000)` returns false if exporter cleanup is still running;
cleanup continues in a daemon thread. It does not shut down an application-owned
provider or its other processors. Finish/close active streams before shutdown.

## Content and spans

`@span`, `@span(name="step")`, and `@span(kind="tool")` preserve function return
values and exceptions. `with span("step") as s:` yields the real OTel span.
`update_trace()` updates the entry span, falling back to the current OTel span.

Content is enabled by default. `init(capture_content=False)` disables content
capture in this package; third-party instrumentors retain their own policies.
`redact(value)` runs before serialization; if it raises, the value is omitted.
`max_content_bytes` defaults to 16 KiB per content attribute. Serialization walks
only built-in containers, with depth/node limits; arbitrary objects become
`[unsupported]`. Oversized custom values become a JSON truncation marker. Message arrays retain a structurally valid prefix, or are omitted if redaction produces an invalid shape. Streaming
capture retains a bounded prefix and marks `confident.span.content_truncated`.
Exception types are recorded without exception messages or stack traces.

Generator decorators start spans on first iteration, detach context between
iterations, and end on exhaustion, close, error, or garbage collection. They
forward send/throw/asend/athrow. Generator yields are not accumulated; a synchronous
generator's final return value is captured. Explicitly close abandoned generators.
Providers capture bounded streaming output separately.

Use `instrumentations=()` when another instrumentor already covers the provider.
Existing wrapt wrappers are not stacked. Enabled native integrations add
`confident.span.integration` to spans from their exact instrumentation scope.
Other attributes, events, and schema URLs retain their native conventions.

See the [Python compatibility matrix](docs/compatibility.md) and
[shared wire contract](../spec/contract.md) for exact
supported surfaces, convention versions, release requirements, and portable receiver fixtures. Backend mapping is developed and validated separately.

## License

Licensed under the [Apache License 2.0](LICENSE). The license is included in both
the wheel and source distribution. Bundled OpenTelemetry material retains its
third-party attribution.

Bedrock examples: [Converse](examples/bedrock/converse.py), [streaming](examples/bedrock/streaming.py), and [asyncio thread offload](examples/bedrock/async_converse.py).
Boto3 uses its normal AWS credential chain. Native async AWS clients are not instrumented.

For implementation layout and adding integrations, see the [architecture guide](docs/architecture.md).


Native integrations: install `pip install confident-trace` in your existing Google
ADK or Microsoft Agent Framework application, then call `init()` on the shared
global OTel provider. Supported installed SDKs are detected automatically; manage
your provider and framework dependencies in your application.

AgentCore additionally needs OTel ASGI instrumentation: install
`pip install 'confident-trace[agentcore]'`. This extra installs the tracing
middleware only; your application supplies `bedrock-agentcore`. Extras add tracing
dependencies, rather than enabling integrations.

See [integration setup and boundaries](docs/integrations.md) and
[examples](examples/README.md). Tested versions are documented; cloud deployment
and backend mapping are separate. Test extras are for development and CI.

## SDK diagnostics

To troubleshoot missing telemetry, enable the SDK's diagnostic logger through
Python logging:

```python
import logging

logging.basicConfig(level=logging.WARNING)
logging.getLogger("confident_trace.diagnostics").setLevel(logging.DEBUG)
```

Failures caught by the shared fail-open helper then produce messages such as
`Telemetry operation integrations.openai.extraction.response failed (TypeError)`.
This is SDK troubleshooting output, not a separate telemetry exporter. Existing
application logging handlers and filters determine where the messages go.

Diagnostics are silent unless DEBUG is enabled for this logger (directly or via
its parent). They include only package code locations and exception type names;
arguments, return values, exception messages, and tracebacks are omitted. External
callables use the generic label `telemetry`. Output is limited to 10 messages per
60-second window per process across all operations; the last message announces
suppression. Enabling diagnostics does not change return values or retry calls.
Logging failures are swallowed and forked children get a fresh limiter.
This covers the shared helper, not every upstream or independently caught failure.


For OpenAI Agents framework tracing, install `confident-trace[openai-agents]` in
addition to your existing `openai-agents` package. This extra adds the OpenInference
tracing bridge. Claude Agent SDK needs no extra; `init()` configures its default
subprocess's native OTLP export. See [setup and boundaries](docs/integrations.md).

### LangChain and LangGraph

Install the frameworks and model integrations your application uses, then call
`init()`. No tracing extra or OpenInference dependency is required. Both frameworks
share one owned callback bridge; `instrumentations=("langgraph",)` also enables it.

```python
from confident_trace import init, span

init()
with span("request"):
    result = graph.invoke(state, {"configurable": {"thread_id": "conversation-42"}})
```

Graph nodes, intermediate runnables, models, tools, and retrievers retain their
callback hierarchy. A model's requested tool calls are captured in its output;
subsequent tool executions follow their framework parent, normally alongside
the model under the agent/node. Conversation IDs associate separate traces;
checkpoint resume starts a new invocation.

See [execution and concurrency details](docs/langchain.md) and the offline
[LangGraph example](examples/langgraph_local.py).

CrewAI is automatically instrumented when installed. See [CrewAI setup and tracing ownership](docs/crewai.md).

LlamaIndex, Agno, and smolagents are automatically instrumented when installed.
See [setup, execution context and model span ownership](docs/frameworks.md).

## Integration labels

`confident_trace.Integration` is the shared string enum of Cloud UI labels.
Package-owned integrations stamp `confident.span.integration` at span creation;
enabled native integrations stamp spans on the shared provider. Provider calls
keep their own SDK label when nested inside framework spans. LangGraph uses
`Integration.LANGCHAIN`, matching its shared callback bridge and Cloud UI.

Existing UI labels are retained exactly, including `LangChain`, `PydanticAI`,
`CrewAI`, `LlamaIndex`, `OpenAI Agents`, `Google ADK`, `Strands`, and `AgentCore`.
New integrations use `Google GenAI`, `Bedrock`, `Microsoft Agent Framework`,
`Agno`, and `Smolagents`; Cloud accepts these strings but has no dedicated icons
for them yet. The enum also includes `OpenRouter`, `OpenTelemetry`, and
`OpenInference` for explicitly attributed external spans.

Claude Agent SDK's label is available as `Integration.CLAUDE_AGENT_SDK`, but its
CLI subprocess exports directly to OTLP and bypasses the Python span processor.
Stamping those remote spans requires support in the CLI or the receiving
Collector; this SDK does not add duplicate local spans.
