mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-02 14:32:45 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
208 lines
9.6 KiB
TypeScript
208 lines
9.6 KiB
TypeScript
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
|
|
|
|
import { StepDefinition } from '../steps'
|
|
|
|
export const getAWSBedrockSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
|
|
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
|
|
|
|
const NotableGenerationProperties = snippets?.NotableGenerationProperties
|
|
|
|
return [
|
|
{
|
|
title: 'Install dependencies',
|
|
badge: 'required',
|
|
content: (
|
|
<>
|
|
<Markdown>
|
|
Install the OpenTelemetry SDK, OTLP exporter, and the AWS SDK instrumentation for your language.
|
|
</Markdown>
|
|
|
|
<CodeBlock
|
|
blocks={[
|
|
{
|
|
language: 'bash',
|
|
file: 'Python',
|
|
code: dedent`
|
|
pip install boto3 opentelemetry-instrumentation-botocore opentelemetry-sdk "insights[otel]"
|
|
`,
|
|
},
|
|
{
|
|
language: 'bash',
|
|
file: 'Node',
|
|
code: dedent`
|
|
npm install @aws-sdk/client-bedrock-runtime @opentelemetry/instrumentation-aws-sdk @opentelemetry/sdk-node @opentelemetry/resources @hanzo/ai
|
|
`,
|
|
},
|
|
]}
|
|
/>
|
|
</>
|
|
),
|
|
},
|
|
{
|
|
title: 'Set up the OpenTelemetry exporter',
|
|
badge: 'required',
|
|
content: (
|
|
<>
|
|
<Markdown>
|
|
Configure the OpenTelemetry SDK to export traces to Insights's OTLP ingestion endpoint. Insights
|
|
converts `gen_ai.*` spans into `$ai_generation` events automatically.
|
|
</Markdown>
|
|
|
|
<CodeBlock
|
|
blocks={[
|
|
{
|
|
language: 'python',
|
|
file: 'Python',
|
|
code: dedent`
|
|
from opentelemetry import trace
|
|
from opentelemetry.sdk.trace import TracerProvider
|
|
from opentelemetry.sdk.resources import Resource, SERVICE_NAME
|
|
from insights.ai.otel import InsightsSpanProcessor
|
|
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
|
|
|
|
resource = Resource(attributes={
|
|
SERVICE_NAME: "my-ai-app",
|
|
})
|
|
|
|
provider = TracerProvider(resource=resource)
|
|
provider.add_span_processor(
|
|
InsightsSpanProcessor(
|
|
api_key="<ph_project_token>",
|
|
host="<ph_client_api_host>",
|
|
)
|
|
)
|
|
trace.set_tracer_provider(provider)
|
|
|
|
BotocoreInstrumentor().instrument()
|
|
`,
|
|
},
|
|
{
|
|
language: 'typescript',
|
|
file: 'Node',
|
|
code: dedent`
|
|
import { NodeSDK } from '@opentelemetry/sdk-node'
|
|
import { resourceFromAttributes } from '@opentelemetry/resources'
|
|
import { InsightsSpanProcessor } from '@hanzo/ai/otel'
|
|
import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk'
|
|
|
|
const sdk = new NodeSDK({
|
|
resource: resourceFromAttributes({
|
|
'service.name': 'my-ai-app',
|
|
}),
|
|
spanProcessors: [
|
|
new InsightsSpanProcessor({
|
|
apiKey: '<ph_project_token>',
|
|
host: '<ph_client_api_host>',
|
|
}),
|
|
],
|
|
instrumentations: [new AwsInstrumentation()],
|
|
})
|
|
sdk.start()
|
|
`,
|
|
},
|
|
]}
|
|
/>
|
|
</>
|
|
),
|
|
},
|
|
{
|
|
title: 'Call Bedrock',
|
|
badge: 'required',
|
|
content: (
|
|
<>
|
|
<Markdown>
|
|
Make Bedrock API calls as normal. The instrumentation automatically captures `gen_ai.*` spans
|
|
for Converse, ConverseStream, InvokeModel, and InvokeModelWithResponseStream operations.
|
|
</Markdown>
|
|
|
|
<CodeBlock
|
|
blocks={[
|
|
{
|
|
language: 'python',
|
|
file: 'Python',
|
|
code: dedent`
|
|
import boto3
|
|
|
|
client = boto3.client("bedrock-runtime", region_name="us-east-1")
|
|
|
|
response = client.converse(
|
|
modelId="openai.gpt-oss-20b-1:0",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": [{"text": "Tell me a fun fact about mascots."}],
|
|
}
|
|
],
|
|
)
|
|
|
|
for block in response["output"]["message"]["content"]:
|
|
if "text" in block:
|
|
print(block["text"])
|
|
break
|
|
`,
|
|
},
|
|
{
|
|
language: 'typescript',
|
|
file: 'Node',
|
|
code: dedent`
|
|
// The AWS SDK must be imported after sdk.start() so the
|
|
// instrumentation can patch it.
|
|
const {
|
|
BedrockRuntimeClient,
|
|
ConverseCommand,
|
|
} = await import('@aws-sdk/client-bedrock-runtime')
|
|
|
|
const client = new BedrockRuntimeClient({ region: 'us-east-1' })
|
|
|
|
const response = await client.send(
|
|
new ConverseCommand({
|
|
modelId: 'openai.gpt-oss-20b-1:0',
|
|
messages: [
|
|
{
|
|
role: 'user',
|
|
content: [{ text: 'Tell me a fun fact about mascots.' }],
|
|
},
|
|
],
|
|
})
|
|
)
|
|
|
|
const textBlock = response.output?.message?.content?.find((b) => 'text' in b)
|
|
console.log(textBlock?.text)
|
|
|
|
await sdk.shutdown()
|
|
`,
|
|
},
|
|
]}
|
|
/>
|
|
|
|
<CalloutBox type="fyi" icon="IconInfo" title="Supported models">
|
|
<Markdown>
|
|
The instrumentation emits `gen_ai.*` spans for **Amazon Titan**, **Amazon Nova**, and
|
|
**Anthropic Claude** models. Tool call instrumentation is available for Amazon Nova and
|
|
Anthropic Claude 3+.
|
|
</Markdown>
|
|
</CalloutBox>
|
|
|
|
<Blockquote>
|
|
<Markdown>
|
|
**Note:** If you want to capture LLM events anonymously, omit the `insights_distinct_id`. See
|
|
our docs on [anonymous vs identified
|
|
events](https://hanzo.ai/docs/data/anonymous-vs-identified-events) to learn more.
|
|
</Markdown>
|
|
</Blockquote>
|
|
|
|
<Markdown>
|
|
{dedent`
|
|
You can expect captured \`$ai_generation\` events to have the following properties:
|
|
`}
|
|
</Markdown>
|
|
|
|
{NotableGenerationProperties && <NotableGenerationProperties />}
|
|
</>
|
|
),
|
|
},
|
|
]
|
|
}
|
|
|
|
export const AWSBedrockInstallation = createInstallation(getAWSBedrockSteps)
|