Integrating Instana with Amazon Bedrock AgentCore

Configure Instana to receive and display trace data from applications that are built and deployed by using Amazon Bedrock AgentCore.

After you complete the following steps, you can configure Instana to receive telemetry data and visualize distributed traces for applications that are deployed in AgentCore.

Create environment configuration

Create a .env file in the root directory of your application code and add the following variables:
OTEL_EXPORTER_OTLP_ENDPOINT="<instana_endpoint>"
INSTANA_KEY="<instana_key>"
 

These variables define the Instana OTLP endpoint and authentication key that is used for exporting telemetry data.

Choosing the correct <instana_endpoint>

Instana supports two OTLP ingestion modes: Agent mode and Agentless mode.

Agent mode

Use this mode when the Instana agent is installed on your machine.

Default OTLP HTTP port: 4318

Example:

OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"

Agentless mode (SaaS OTLP ingest)

Use this mode when you send telemetry directly to Instana Cloud.

Example:

OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-magenta-saas.instana.rocks:4318"
Note: The endpoint URL varies by region (magenta, yellow, pink, etc.). Replace `magenta` with your region's color code. For a complete list of regional endpoints, see Endpoints of the Instana backend otlp-acceptor.

OTLP authentication header for Instana

You do not need to manually construct the OTLP header. Add your Instana API key in the .env file, and the application generates the header automatically by using the following logic:
otel_auth_header = f"x-instana-key={instana_key}"

Example of the generated header

If your .env file contains:
INSTANA_KEY="abcd1234xyz"
The application internally generates the following header:
OTEL_EXPORTER_OTLP_HEADERS="x-instana-key=abcd1234xyz"

Enable telemetry export in the AgentCore application

Add the following code snippet to your application to configure telemetry export to Instana:
from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Fetch configuration
otel_endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
instana_key = os.getenv("INSTANA_KEY")

# Format Instana header
otel_auth_header = f"x-instana-key={instana_key}"

# Launch the AgentCore runtime
launch_result = agentcore_runtime.launch(
    env_vars={
        "BEDROCK_MODEL_ID": "amazon.nova-lite-v1:0",
        "OTEL_EXPORTER_OTLP_ENDPOINT": otel_endpoint,
        "OTEL_EXPORTER_OTLP_HEADERS": otel_auth_header,
        "OTEL_SERVICE_NAME": "AWS-APP",
        "OTEL_EXPORTER_OTLP_INSECURE": "false",
        "DISABLE_ADOT_OBSERVABILITY": "true",
    }
)

launch_result

This configuration enables OpenTelemetry-based tracing and exports the trace data to Instana.