Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions features/observability/traces/auto-instrumentation/anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ This guide covers the Anthropic model SDK. If you use the Claude Agent SDK or Cl

## Supported APIs

| Anthropic API | Python | JavaScript |
| API surface | Python | JavaScript |
| --- | --- | --- |
| Messages (`messages.create`) | Sync and async | Supported |
| Messages streaming | `messages.create(..., stream=True)` and `messages.stream()`; sync and async | `messages.create({ stream: true })` |
| Structured message parsing (`messages.parse`) | Sync and async | Not supported |
| Beta Messages | Not included in the documented Python surface | Create and streaming |
| Messages (`messages.create`) | Supported (sync and async) | Supported |
| Messages streaming | Supported (`messages.create(..., stream=True)` and `messages.stream()`; sync and async) | Supported (`messages.create({ stream: true })`) |
| Structured message parsing (`messages.parse`) | Supported (sync and async) | Not supported |
| Beta Messages | Not documented | Supported |
| Beta Messages streaming | Not documented | Supported |
| Anthropic Vertex | Supported | Supported |

Anthropic Bedrock is not included in JavaScript provider auto-instrumentation. Other Anthropic SDK calls continue to work normally, but unsupported surfaces do not automatically create PromptLayer traces or request logs.
`Not documented` means the surface is outside the verified coverage for that language.

The Anthropic Bedrock client is not included in this provider integration. To trace direct Boto3 or AWS SDK v3 Bedrock Runtime calls, follow the [AWS Bedrock guide](/features/observability/traces/auto-instrumentation/bedrock). Other Anthropic SDK calls continue to work normally, but unsupported surfaces do not automatically create PromptLayer traces or request logs.

## Prerequisites

Expand All @@ -35,7 +38,7 @@ export PROMPTLAYER_API_KEY="pl_..."
export ANTHROPIC_API_KEY="sk-ant-..."
```

PromptLayer strongly recommends setting the language-specific [content-capture value](/features/observability/traces/auto-instrumentation/overview#capture-prompts-and-responses) so request inspection, search, analytics, and debugging can use prompts, responses, and tool content.
PromptLayer captures supported message content by default. Review the [content-capture behavior and opt-out values](/features/observability/traces/auto-instrumentation/overview#capture-prompts-and-responses) before sending provider requests.

## Python

Expand Down
123 changes: 96 additions & 27 deletions features/observability/traces/auto-instrumentation/bedrock.mdx
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
---
title: "AWS Bedrock"
description: "Automatically trace supported direct Amazon Bedrock Runtime calls made with Boto3."
description: "Automatically trace supported direct Amazon Bedrock Runtime calls made with Boto3 or AWS SDK v3."
icon: "aws"
---

PromptLayer can auto-instrument Boto3 calls to Amazon Bedrock Runtime and export supported operations as OpenTelemetry spans. Each supported direct Bedrock call appears in PromptLayer as both a trace span and an associated request log without replacing the Boto3 client.
PromptLayer can auto-instrument Amazon Bedrock Runtime calls made with Boto3 or AWS SDK v3 and export supported operations as OpenTelemetry spans. Each supported direct Bedrock call appears in PromptLayer as both a trace span and an associated request log without replacing the native AWS client.

<Note>
This Python integration covers direct Boto3 `bedrock-runtime` calls. It does not instrument `aioboto3`, Anthropic's Bedrock client, or the AWS SDK for JavaScript.
This integration covers direct Boto3 `bedrock-runtime` calls in Python and `@aws-sdk/client-bedrock-runtime` calls in JavaScript. It does not instrument `aioboto3` or the separate Anthropic Bedrock client.
</Note>

## Supported APIs

| Boto3 Bedrock Runtime method | Python |
| --- | --- |
| Converse (`converse`) | Supported |
| Converse streaming (`converse_stream`) | Supported |
| InvokeModel (`invoke_model`) | Supported |
| InvokeModel streaming (`invoke_model_with_response_stream`) | Supported |
| API surface | Python | JavaScript |
| --- | --- | --- |
| Converse | Supported (`client.converse(...)`) | Supported (`ConverseCommand`) |
| Converse streaming | Supported (`client.converse_stream(...)`) | Not supported |
| InvokeModel | Supported (`client.invoke_model(...)`) | Not supported |
| InvokeModel streaming | Supported (`client.invoke_model_with_response_stream(...)`) | Not supported |

Only the Bedrock Runtime operations in this table receive Bedrock-specific PromptLayer request log enrichment. For streaming operations, consume or close the response stream before flushing so the span can finish.
Only the language-specific surfaces in this table receive Bedrock-specific PromptLayer request log enrichment. In Python, consume or close a streaming response before flushing so its span can finish.

<Warning>
Bedrock auto-instrumentation uses the OpenTelemetry Botocore instrumentor. Enabling it also traces other Botocore service calls made by the same process, although Bedrock-specific request log enrichment applies only to the supported `bedrock-runtime` operations.
Bedrock auto-instrumentation uses the general OpenTelemetry Botocore or AWS SDK instrumentor. Enabling it can also trace other AWS SDK service calls made by the same process, although Bedrock-specific request log enrichment applies only to the supported Bedrock Runtime operations.
</Warning>

## Prerequisites

- A [PromptLayer API key](/quickstart#prerequisites) for the workspace that should receive the traces
- AWS credentials, a region, and access to the Bedrock model or inference profile your application calls
- Python 3.10 or later
- Python 3.10 or later for Python, or Node.js 20 or later for JavaScript

Export the PromptLayer API key before the application starts. The example below also uses `AWS_REGION` and `AWS_BEDROCK_MODEL` as application configuration:

```bash
export PROMPTLAYER_API_KEY="pl_..."
export AWS_REGION="us-east-1"
export AWS_BEDROCK_MODEL="your-model-or-inference-profile-id"
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT="span_only"
```

PromptLayer strongly recommends enabling content capture when your data policies allow it so request inspection, search, analytics, and debugging can use Bedrock messages and tool content.
PromptLayer captures supported Bedrock message content by default. Review [Capture Prompts and Responses](#capture-prompts-and-responses) before sending provider requests.

## Python

Expand Down Expand Up @@ -85,9 +84,9 @@ finally:
tracer_provider.force_flush()
```

The canonical selector is `bedrock`. The `amazon.bedrock` and `aws.bedrock` aliases select the same Botocore instrumentor.
The canonical selector is `bedrock`. Python also accepts `amazon.bedrock` and `aws.bedrock` as aliases for the same Botocore instrumentor.

<Accordion title="Use an existing PromptLayer client">
<Accordion title="Use an existing Python PromptLayer client">
If your application already creates a PromptLayer client, select Bedrock when enabling tracing:

```python
Expand All @@ -104,33 +103,103 @@ client = boto3.client("bedrock-runtime", region_name="us-east-1")
Omit `tracing_providers` to instrument every supported provider SDK that is installed.
</Accordion>

## JavaScript

### 1. Install the SDKs

```bash
npm install promptlayer @aws-sdk/client-bedrock-runtime
```

### 2. Preload PromptLayer instrumentation

The preload must run before the application imports the AWS SDK client:

```bash
node --import promptlayer/register app.mjs
```

### 3. Use the AWS SDK normally

```javascript
import {
BedrockRuntimeClient,
ConverseCommand,
} from "@aws-sdk/client-bedrock-runtime";
import { shutdownTracing } from "promptlayer";

const client = new BedrockRuntimeClient({
region: process.env.AWS_REGION,
});

try {
const response = await client.send(
new ConverseCommand({
modelId: process.env.AWS_BEDROCK_MODEL,
messages: [
{
role: "user",
content: [
{ text: "Explain distributed tracing in one sentence." },
],
},
],
inferenceConfig: { maxTokens: 128 },
}),
);
console.log(
response.output?.message?.content
?.map((block) => block.text ?? "")
.join(""),
);
} finally {
client.destroy();
await shutdownTracing();
}
```

The preload instruments every supported provider. To instrument only Bedrock, call `configureTracing({ providers: ["bedrock"] })` in a bootstrap module and dynamically import the application afterward. See [Select Providers](/features/observability/traces/auto-instrumentation/overview#select-providers).

## Capture Prompts and Responses

Bedrock request and response content is disabled by default because it can contain sensitive data. Set `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=span_only` before configuring tracing to add supported message content to PromptLayer spans.
PromptLayer captures supported Bedrock request and response content by default. To export metadata-only telemetry, opt out before tracing is configured:

<CodeGroup>
```bash Python
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT="NO_CONTENT"
```

```bash JavaScript
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT="false"
```
</CodeGroup>

JavaScript can instead pass `captureContent: false` to `configureTracing()`.

Content coverage differs by Bedrock Runtime operation:

| Operation | Content added to the PromptLayer span |
| --- | --- |
| `converse` | Request messages, system instructions, and the response message |
| `converse_stream` | Request messages and system instructions; streamed response content is not added |
| `invoke_model` and `invoke_model_with_response_stream` | Request and response bodies are not added |
| Operation | Python content | JavaScript content |
| --- | --- | --- |
| Converse | Request messages, system instructions, and the response message | Request messages, system instructions, and the response message |
| Converse streaming | Request messages and system instructions; streamed response content is not added | Not instrumented |
| InvokeModel and InvokeModel streaming | Request and response bodies are not added | Not instrumented |

All supported operations still include non-content telemetry supplied by the instrumentor, such as the model, timing, token usage when available, and errors.

<Warning>
Content capture can send user messages, model responses, system instructions, tool arguments and results, and other application data to PromptLayer. Review your privacy, retention, and compliance requirements before enabling it.
Content capture can send user messages, model responses, system instructions, tool arguments and results, and other application data to PromptLayer. Because it is enabled by default, review your privacy, retention, and compliance requirements and opt out before the first Bedrock request when necessary.
</Warning>

## Verify the Integration

Run one supported Bedrock Runtime request, consume any response stream, flush tracing, and open [Traces](/features/observability/traces) in PromptLayer. The Bedrock span should have an associated request log and identify the Converse or InvokeModel API.
Run one supported Bedrock Runtime request, consume any Python response stream, flush or shut down tracing, and open [Traces](/features/observability/traces) in PromptLayer. The Bedrock span should have an associated request log and identify the Converse or InvokeModel API.

If no span appears:

- Confirm instrumentation is configured before the first Bedrock Runtime request.
- Confirm the Boto3 client uses `bedrock-runtime` and a method listed in [Supported APIs](#supported-apis).
- Confirm the client and operation are listed for your language in [Supported APIs](#supported-apis).
- In JavaScript, confirm the preload or bootstrap runs before `@aws-sdk/client-bedrock-runtime` loads.
- Confirm `PROMPTLAYER_API_KEY` belongs to the workspace you are checking.
- For streaming calls, fully consume or close the stream before flushing.
- For Python streaming calls, fully consume or close the stream before flushing.
- Flush tracing before a short-lived process exits.
- If only message content is missing, check the content-capture value and the operation-specific coverage above, then restart the process.
- If only message content is missing, confirm content capture was not disabled, check the operation-specific coverage above, and restart the process after changing the setting.
18 changes: 11 additions & 7 deletions features/observability/traces/auto-instrumentation/google.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ PromptLayer can auto-instrument the Google GenAI SDK in both Gemini Developer AP

## Supported APIs

| Google GenAI API | Python | JavaScript |
| API surface | Python | JavaScript |
| --- | --- | --- |
| Generate Content | Sync and async | Supported |
| Streaming Generate Content | Sync and async | Supported |
| Embeddings | Sync and async | Not supported |
| Interactions | Sync and async in supported Google GenAI SDK releases | Not supported |
| Generate Content | Supported (sync and async) | Supported |
| Generate Content streaming | Supported (sync and async) | Supported |
| Chat | Not documented | Supported (`sendMessage`) |
| Chat streaming | Not documented | Supported (`sendMessageStream`) |
| Embeddings | Supported (sync and async) | Not supported |
| Interactions | Supported (sync and async in supported SDK releases) | Not supported |
| Vertex AI mode | Supported | Supported |

In JavaScript, chat `sendMessage` and `sendMessageStream` calls are also traced. Other Google GenAI SDK calls continue to work normally, but unsupported surfaces do not automatically create PromptLayer traces or request logs.
`Not documented` means the surface is outside the verified coverage for that language.

Other Google GenAI SDK calls continue to work normally, but unsupported surfaces do not automatically create PromptLayer traces or request logs.

## Prerequisites

Expand All @@ -31,7 +35,7 @@ export PROMPTLAYER_API_KEY="pl_..."
export GOOGLE_API_KEY="..."
```

PromptLayer strongly recommends setting the language-specific [content-capture value](/features/observability/traces/auto-instrumentation/overview#capture-prompts-and-responses) so request inspection, search, analytics, and debugging can use prompts, responses, and tool content.
PromptLayer captures supported message content by default. Review the [content-capture behavior and opt-out values](/features/observability/traces/auto-instrumentation/overview#capture-prompts-and-responses) before sending provider requests.

## Python

Expand Down
Loading
Loading