Skip to main content

Overview

This guide shows you how to integrate Latitude Telemetry into an existing application that uses Amazon Bedrock via the AWS SDK. After completing these steps:
  • Every Bedrock model invocation can be captured as a log in Latitude.
  • Logs are attached to a specific prompt and version in Latitude.
  • You can annotate, evaluate, and debug your Bedrock-powered features from the Latitude dashboard.
You’ll keep calling Bedrock directly — Telemetry simply observes and enriches those calls.

Requirements

Before you start, make sure you have:
  • A Latitude account and API key.
  • At least one prompt created in Latitude.
  • A Node.js-based project that uses @aws-sdk/client-bedrock-runtime.

Steps

1

Install requirements

Add the Latitude Telemetry package to your project:
npm add @latitude-data/telemetry @opentelemetry/api
2

Initialize Latitude Telemetry with Bedrock

Create a LatitudeTelemetry instance and pass the Bedrock Runtime client module as an instrumentation.
import { LatitudeTelemetry } from '@latitude-data/telemetry'
import * as Bedrock from '@aws-sdk/client-bedrock-runtime'

export const telemetry = new LatitudeTelemetry('your-latitude-api-key', {
  instrumentations: {
    bedrock: Bedrock, // Enables automatic tracing for Bedrock Runtime
  },
})
3

Wrap your Bedrock-powered feature

Wrap the code that calls Bedrock with a Telemetry prompt span, and execute your Bedrock call inside that span.
import { context } from '@opentelemetry/api'
import { BACKGROUND } from '@latitude-data/telemetry'
import {
  BedrockRuntimeClient,
  InvokeModelCommand,
} from '@aws-sdk/client-bedrock-runtime'
import { telemetry } from './telemetry'

export async function generateSupportReply(input: string) {
  const $prompt = telemetry.prompt(BACKGROUND(), {
    promptUuid: 'your-prompt-uuid',
    versionUuid: 'your-version-uuid',
  })

  await context
    .with($prompt.context, async () => {
      const client = new BedrockRuntimeClient({ region: 'us-east-1' })

      const response = await client.send(
        new InvokeModelCommand({
          modelId: 'anthropic.claude-3-sonnet-20240229-v1:0',
          body: JSON.stringify({
            prompt: input,
          }),
          contentType: 'application/json',
          accept: 'application/json',
        }),
      )

      // Use response here...
    })
    .then(() => $prompt.end())
    .catch((error) => $prompt.fail(error as Error))
    .finally(() => telemetry.flush())
}

Seeing your logs in Latitude

Once you’ve wrapped your Bedrock-powered feature, you can see your logs in Latitude.
  1. Go to the Traces section of your prompt in Latitude.
  2. You should see new entries every time your code is executed, including:
    • Input/output payloads
    • Model ID
    • Latency and error information