Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(aio): show per-request context in otel onboarding docs (#117555)

Carlos Marchal29af8f0f2a6f
diff --git a/docs/onboarding/ai-observability/_snippets/otel-request-context.tsx b/docs/onboarding/ai-observability/_snippets/otel-request-context.tsx
new file mode 100644
index 000000000000..c4ef9bc50473
--- /dev/null
+++ b/docs/onboarding/ai-observability/_snippets/otel-request-context.tsx
@@ -0,0 +1,142 @@
+import { OnboardingComponentsContext } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { StepDefinition } from '../../steps'
+
+export interface OtelRequestContextConfig {
+ /** Language tabs the surrounding page shows, in the order it shows them. */
+ languages: ('Python' | 'Node' | 'Go')[]
+ /** The tracer setup class the page's Node setup step uses. Defaults to `NodeSDK`. */
+ nodeTracerSetup?: 'NodeSDK' | 'NodeTracerProvider'
+}
+
+const PYTHON_CODE = `
+# Requires posthog 7.70.0 or later
+import posthog
+
+with posthog.new_context():
+ posthog.identify_context(user_id)
+ posthog.tag("$ai_session_id", conversation_id)
+ posthog.tag("plan", "pro") # custom properties work too
+
+ reply = handle_turn(user_message)
+`.trim()
+
+const NODE_SETUP_VARIABLES = { NodeSDK: 'sdk', NodeTracerProvider: 'provider' }
+
+const getNodeCode = (tracerSetup: 'NodeSDK' | 'NodeTracerProvider'): string =>
+ `
+// Requires @posthog/ai 8.14.0 and posthog-node 5.15.0 or later
+import { PostHog } from 'posthog-node'
+
+const posthog = new PostHog('<ph_project_token>', { host: '<ph_client_api_host>' })
+
+const ${NODE_SETUP_VARIABLES[tracerSetup]} = new ${tracerSetup}({
+ // ...the rest of your setup from the earlier step
+ spanProcessors: [
+ new PostHogSpanProcessor({
+ projectToken: '<ph_project_token>',
+ host: '<ph_client_api_host>',
+ client: posthog,
+ }),
+ ],
+})
+
+const reply = await posthog.withContext(
+ {
+ distinctId: userId,
+ properties: {
+ $ai_session_id: conversationId,
+ plan: 'pro', // custom properties work too
+ },
+ },
+ () => handleTurn(userMessage)
+)
+`.trim()
+
+const GO_CODE = `
+// Requires github.com/posthog/posthog-go/otel v1.35.0 or later
+import "github.com/posthog/posthog-go"
+
+ctx = posthog.WithRequestContext(ctx, posthog.RequestContext{
+ DistinctId: userID,
+ Properties: posthog.Properties{
+ "$ai_session_id": conversationID,
+ "plan": "pro", // custom properties work too
+ },
+})
+
+reply := handleTurn(ctx, userMessage)
+`.trim()
+
+const getCodeBlock = (
+ language: OtelRequestContextConfig['languages'][number],
+ config: OtelRequestContextConfig
+): { language: string; file: string; code: string } => {
+ switch (language) {
+ case 'Python':
+ return { language: 'python', file: 'Python', code: PYTHON_CODE }
+ case 'Node':
+ return { language: 'typescript', file: 'Node', code: getNodeCode(config.nodeTracerSetup ?? 'NodeSDK') }
+ case 'Go':
+ return { language: 'go', file: 'Go', code: GO_CODE }
+ }
+}
+
+export const getOtelRequestContextStep = (
+ ctx: OnboardingComponentsContext,
+ config: OtelRequestContextConfig
+): StepDefinition => {
+ const { CodeBlock, Markdown, dedent } = ctx
+
+ return {
+ title: 'Users and sessions',
+ badge: 'recommended',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ A server usually handles requests for many users, so a resource attribute can't say who
+ each trace belongs to. Wrap each request in a PostHog context instead. The PostHog span
+ processor adds the context's distinct ID and properties to every AI span started inside it.
+ Other span processors and exporters on the same provider don't see them.
+
+ Set \`$ai_session_id\` if your product has multi-turn conversations, so the Sessions tab can
+ group their traces. Workloads that finish in a single trace, like batch jobs or one-shot
+ generation, don't need it.
+ `}
+ </Markdown>
+
+ <CodeBlock blocks={config.languages.map((language) => getCodeBlock(language, config))} />
+
+ {config.languages.includes('Node') && (
+ <Markdown>
+ {dedent`
+ On Node, install \`posthog-node\` and pass the client as the \`client\` option of your
+ \`PostHogSpanProcessor\`. Without it, the processor doesn't read the context.
+ `}
+ </Markdown>
+ )}
+
+ {config.languages.includes('Go') && (
+ <Markdown>
+ {dedent`
+ In Go, \`posthog.NewRequestContextMiddleware\` fills the context for each HTTP request
+ from the \`X-PostHog-Distinct-Id\` and \`X-PostHog-Session-Id\` headers. The session
+ header sets the web session ID (\`$session_id\`), not \`$ai_session_id\`, so set
+ \`$ai_session_id\` in \`Properties\` to group traces in the Sessions tab.
+ `}
+ </Markdown>
+ )}
+
+ <Markdown>
+ {dedent`
+ A distinct ID set this way takes priority over a \`posthog.distinct_id\` resource attribute,
+ so you can keep the resource attribute as the fallback for work outside a request. If your
+ instrumentation already sets the \`gen_ai.conversation.id\` attribute, PostHog uses it as
+ the session ID, and an explicit \`$ai_session_id\` takes priority over it.
+ `}
+ </Markdown>
+ </>
+ ),
+ }
+}
diff --git a/docs/onboarding/ai-observability/_snippets/otel-session-id.tsx b/docs/onboarding/ai-observability/_snippets/otel-session-id.tsx
deleted file mode 100644
index 8b6bf148b31d..000000000000
--- a/docs/onboarding/ai-observability/_snippets/otel-session-id.tsx
+++ /dev/null
@@ -1,157 +0,0 @@
-import { OnboardingComponentsContext } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
-
-import { StepDefinition } from '../../steps'
-
-export interface OtelSessionIdConfig {
- /** Language tabs the surrounding page shows, in the order it shows them. */
- languages: ('Python' | 'Node' | 'Go')[]
-}
-
-const PYTHON_CODE = `
-import contextvars
-from collections.abc import Iterator
-from contextlib import contextmanager
-from typing import Optional
-
-from opentelemetry.context import Context
-from opentelemetry.sdk.trace import Span, SpanProcessor
-
-session_id_var: contextvars.ContextVar[Optional[str]] = contextvars.ContextVar(
- "ai_session_id", default=None
-)
-
-
-class SessionIdSpanProcessor(SpanProcessor):
- def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None:
- session_id = session_id_var.get()
- if session_id is not None:
- span.set_attribute("$ai_session_id", session_id)
-
-
-@contextmanager
-def ai_session(session_id: str) -> Iterator[None]:
- token = session_id_var.set(session_id)
- try:
- yield
- finally:
- session_id_var.reset(token)
-
-
-# Register it on the same provider as PostHogSpanProcessor
-provider.add_span_processor(SessionIdSpanProcessor())
-
-# Resetting on exit keeps the ID off the next request that reuses this thread
-with ai_session("conversation-abc"):
- reply = handle_turn(user_message)
-`.trim()
-
-const NODE_CODE = `
-import { AsyncLocalStorage } from 'node:async_hooks'
-import type { Span, SpanProcessor } from '@opentelemetry/sdk-trace-base'
-
-const sessionStore = new AsyncLocalStorage<string>()
-
-class SessionIdSpanProcessor implements SpanProcessor {
- onStart(span: Span): void {
- const sessionId = sessionStore.getStore()
- if (sessionId) {
- span.setAttribute('$ai_session_id', sessionId)
- }
- }
- onEnd(): void {}
- async shutdown(): Promise<void> {}
- async forceFlush(): Promise<void> {}
-}
-
-// Every span started inside the callback carries this session ID
-const reply = await sessionStore.run('conversation-abc', () => handleTurn(userMessage))
-`.trim()
-
-const GO_CODE = `
-import (
- "context"
-
- "go.opentelemetry.io/otel/attribute"
- sdktrace "go.opentelemetry.io/otel/sdk/trace"
-)
-
-type sessionKey struct{}
-
-// WithAISession returns a context whose spans carry this session ID.
-func WithAISession(ctx context.Context, sessionID string) context.Context {
- return context.WithValue(ctx, sessionKey{}, sessionID)
-}
-
-type SessionIDSpanProcessor struct{}
-
-func (SessionIDSpanProcessor) OnStart(parent context.Context, span sdktrace.ReadWriteSpan) {
- if sessionID, ok := parent.Value(sessionKey{}).(string); ok {
- span.SetAttributes(attribute.String("$ai_session_id", sessionID))
- }
-}
-func (SessionIDSpanProcessor) OnEnd(sdktrace.ReadOnlySpan) {}
-func (SessionIDSpanProcessor) Shutdown(context.Context) error { return nil }
-func (SessionIDSpanProcessor) ForceFlush(context.Context) error { return nil }
-
-// Register it on the same provider as the PostHog processor:
-// sdktrace.WithSpanProcessor(SessionIDSpanProcessor{})
-
-// Every span started from this context carries the session ID
-ctx = WithAISession(ctx, "conversation-abc")
-reply := handleTurn(ctx, userMessage)
-`.trim()
-
-const CODE_BY_LANGUAGE = {
- Python: { language: 'python', file: 'Python', code: PYTHON_CODE },
- Node: { language: 'typescript', file: 'Node', code: NODE_CODE },
- Go: { language: 'go', file: 'Go', code: GO_CODE },
-}
-
-export const getOtelSessionIdStep = (ctx: OnboardingComponentsContext, config: OtelSessionIdConfig): StepDefinition => {
- const { CodeBlock, Markdown, dedent } = ctx
-
- return {
- title: 'Group traces into sessions',
- badge: 'optional',
- content: (
- <>
- <Markdown>
- {dedent`
- PostHog groups traces into a session when they share an \`$ai_session_id\`. Set it if your
- product has multi-turn conversations, so the Sessions tab can reconstruct them. Workloads
- that finish in a single trace, like batch jobs or one-shot generation, do not need it.
-
- The instrumentation creates the LLM span for you, so there is no call to pass the session ID
- to. Add a span processor that sets the \`$ai_session_id\` attribute as each span starts.
- PostHog forwards span attributes it does not recognize onto the event, so the value arrives
- as the \`$ai_session_id\` property.
-
- If your instrumentation already sets the \`gen_ai.conversation.id\` attribute, PostHog uses
- it as the session ID and you can skip this step. An explicit \`$ai_session_id\` takes
- priority.
- `}
- </Markdown>
-
- <CodeBlock blocks={config.languages.map((language) => CODE_BY_LANGUAGE[language])} />
-
- {config.languages.includes('Node') && (
- <Markdown>
- {dedent`
- On Node, add \`new SessionIdSpanProcessor()\` to the \`spanProcessors\` array of the
- \`NodeSDK\` you configured earlier, next to \`PostHogSpanProcessor\`. Keep the rest of
- that setup as it is, including \`instrumentations\` and the \`sdk.start()\` call.
- `}
- </Markdown>
- )}
-
- <Markdown>
- {dedent`
- If a process only ever handles one session, set \`$ai_session_id\` as a resource attribute
- next to \`service.name\` instead. Resource attributes apply to every span the process emits,
- so that only works when the process and the session are the same thing.
- `}
- </Markdown>
- </>
- ),
- }
-}
diff --git a/docs/onboarding/ai-observability/autogen.tsx b/docs/onboarding/ai-observability/autogen.tsx
index d00ba0a7c46a..990b866d1b79 100644
--- a/docs/onboarding/ai-observability/autogen.tsx
+++ b/docs/onboarding/ai-observability/autogen.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getAutoGenSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -109,9 +109,10 @@ export const getAutoGenSteps = (ctx: OnboardingComponentsContext): StepDefinitio
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -125,7 +126,7 @@ export const getAutoGenSteps = (ctx: OnboardingComponentsContext): StepDefinitio
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python'] }),
]
}
diff --git a/docs/onboarding/ai-observability/aws-bedrock.tsx b/docs/onboarding/ai-observability/aws-bedrock.tsx
index 1d42198a39b1..4f0e4567196d 100644
--- a/docs/onboarding/ai-observability/aws-bedrock.tsx
+++ b/docs/onboarding/ai-observability/aws-bedrock.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { PROSE_LANGUAGE, StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getAWSBedrockSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -191,9 +191,10 @@ export const getAWSBedrockSteps = (ctx: OnboardingComponentsContext): StepDefini
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog_distinct_id`. See
- our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -207,7 +208,7 @@ export const getAWSBedrockSteps = (ctx: OnboardingComponentsContext): StepDefini
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python', 'Node'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python', 'Node'] }),
]
}
diff --git a/docs/onboarding/ai-observability/claude-platform.tsx b/docs/onboarding/ai-observability/claude-platform.tsx
index 791f34af0494..4cae20a930c1 100644
--- a/docs/onboarding/ai-observability/claude-platform.tsx
+++ b/docs/onboarding/ai-observability/claude-platform.tsx
@@ -1,6 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
const ADD_DESTINATION_SCREENSHOT = '/images/docs/ai-observability/claude-platform-add-destination.png'
const MANAGED_AGENTS_TRACE_SCREENSHOT = '/images/docs/ai-observability/claude-platform-managed-agents-trace.png'
@@ -393,6 +394,24 @@ const getSendTracesStep = (ctx: OnboardingComponentsContext): StepDefinition =>
}
}
+const getRequestContextStep = (ctx: OnboardingComponentsContext): StepDefinition => {
+ const { Markdown } = ctx
+ const step = getOtelRequestContextStep(ctx, {
+ languages: ['Python', 'Node', 'Go'],
+ nodeTracerSetup: 'NodeTracerProvider',
+ })
+
+ return {
+ ...step,
+ content: (
+ <>
+ <Markdown>This step applies to SDK tracing in Python, Node, and Go.</Markdown>
+ {step.content}
+ </>
+ ),
+ }
+}
+
const getSeeTraceStep = (ctx: OnboardingComponentsContext): StepDefinition => {
const { Markdown, ProductScreenshot, dedent } = ctx
@@ -455,6 +474,7 @@ export const getClaudePlatformSteps = (ctx: OnboardingComponentsContext): StepDe
getProjectTokenStep(ctx),
getSendTracesStep(ctx),
getSeeTraceStep(ctx),
+ getRequestContextStep(ctx),
getTroubleshootingStep(ctx),
]
diff --git a/docs/onboarding/ai-observability/instructor.tsx b/docs/onboarding/ai-observability/instructor.tsx
index fc8a6af646d8..a4fa7b0a4cb6 100644
--- a/docs/onboarding/ai-observability/instructor.tsx
+++ b/docs/onboarding/ai-observability/instructor.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getInstructorSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -188,9 +188,10 @@ export const getInstructorSteps = (ctx: OnboardingComponentsContext): StepDefini
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -204,7 +205,7 @@ export const getInstructorSteps = (ctx: OnboardingComponentsContext): StepDefini
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python', 'Node'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python', 'Node'] }),
]
}
diff --git a/docs/onboarding/ai-observability/llamaindex.tsx b/docs/onboarding/ai-observability/llamaindex.tsx
index 2af1aaacf1f1..b94396cf380f 100644
--- a/docs/onboarding/ai-observability/llamaindex.tsx
+++ b/docs/onboarding/ai-observability/llamaindex.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getLlamaIndexSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -120,9 +120,10 @@ export const getLlamaIndexSteps = (ctx: OnboardingComponentsContext): StepDefini
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -136,7 +137,7 @@ export const getLlamaIndexSteps = (ctx: OnboardingComponentsContext): StepDefini
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python'] }),
]
}
diff --git a/docs/onboarding/ai-observability/mirascope.tsx b/docs/onboarding/ai-observability/mirascope.tsx
index 9e5dc8d48c10..f740f8c134bb 100644
--- a/docs/onboarding/ai-observability/mirascope.tsx
+++ b/docs/onboarding/ai-observability/mirascope.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getMirascopeSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -115,9 +115,10 @@ export const getMirascopeSteps = (ctx: OnboardingComponentsContext): StepDefinit
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -131,7 +132,7 @@ export const getMirascopeSteps = (ctx: OnboardingComponentsContext): StepDefinit
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python'] }),
]
}
diff --git a/docs/onboarding/ai-observability/opentelemetry.tsx b/docs/onboarding/ai-observability/opentelemetry.tsx
index ae9da6ea77f8..0b5acfc99d75 100644
--- a/docs/onboarding/ai-observability/opentelemetry.tsx
+++ b/docs/onboarding/ai-observability/opentelemetry.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getOpenTelemetrySteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -43,7 +43,7 @@ export const getOpenTelemetrySteps = (ctx: OnboardingComponentsContext): StepDef
language: 'bash',
file: 'Node',
code: dedent`
- npm install openai @posthog/ai @opentelemetry/sdk-node @opentelemetry/resources @opentelemetry/instrumentation-openai
+ npm install openai @posthog/ai posthog-node @opentelemetry/sdk-node @opentelemetry/resources @opentelemetry/instrumentation-openai
`,
},
{
@@ -278,7 +278,7 @@ export const getOpenTelemetrySteps = (ctx: OnboardingComponentsContext): StepDef
<Blockquote>
<Markdown>
{dedent`
- **Note:** If you want to capture LLM events anonymously, omit the \`posthog.distinct_id\` resource attribute. See our docs on [anonymous vs identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the \`posthog.distinct_id\` resource attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
`}
</Markdown>
</Blockquote>
@@ -335,7 +335,7 @@ export const getOpenTelemetrySteps = (ctx: OnboardingComponentsContext): StepDef
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python', 'Node', 'Go'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python', 'Node', 'Go'] }),
{
title: 'Other instrumentations, direct OTLP, and troubleshooting',
badge: 'optional',
diff --git a/docs/onboarding/ai-observability/pydantic-ai.tsx b/docs/onboarding/ai-observability/pydantic-ai.tsx
index 3da540a70e73..a7730fb0dfe3 100644
--- a/docs/onboarding/ai-observability/pydantic-ai.tsx
+++ b/docs/onboarding/ai-observability/pydantic-ai.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getPydanticAISteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -103,9 +103,10 @@ export const getPydanticAISteps = (ctx: OnboardingComponentsContext): StepDefini
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -119,7 +120,7 @@ export const getPydanticAISteps = (ctx: OnboardingComponentsContext): StepDefini
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python'] }),
]
}
diff --git a/docs/onboarding/ai-observability/semantic-kernel.tsx b/docs/onboarding/ai-observability/semantic-kernel.tsx
index dd819db65193..c09ed90bced2 100644
--- a/docs/onboarding/ai-observability/semantic-kernel.tsx
+++ b/docs/onboarding/ai-observability/semantic-kernel.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getSemanticKernelSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -109,9 +109,10 @@ export const getSemanticKernelSteps = (ctx: OnboardingComponentsContext): StepDe
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -125,7 +126,7 @@ export const getSemanticKernelSteps = (ctx: OnboardingComponentsContext): StepDe
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python'] }),
]
}
diff --git a/docs/onboarding/ai-observability/smolagents.tsx b/docs/onboarding/ai-observability/smolagents.tsx
index 41d51df6c615..8ca58605f090 100644
--- a/docs/onboarding/ai-observability/smolagents.tsx
+++ b/docs/onboarding/ai-observability/smolagents.tsx
@@ -1,7 +1,7 @@
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
-import { getOtelSessionIdStep } from './_snippets/otel-session-id'
+import { getOtelRequestContextStep } from './_snippets/otel-request-context'
export const getSmolagentsSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, CalloutBox, Markdown, Blockquote, dedent, snippets } = ctx
@@ -101,9 +101,10 @@ export const getSmolagentsSteps = (ctx: OnboardingComponentsContext): StepDefini
<Blockquote>
<Markdown>
- **Note:** If you want to capture LLM events anonymously, omit the `posthog.distinct_id`
- resource attribute. See our docs on [anonymous vs identified
- events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more.
+ **Note:** To capture LLM events anonymously, omit the `posthog.distinct_id` resource
+ attribute and don't set a distinct ID in the PostHog context. See our docs on [anonymous vs
+ identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn
+ more.
</Markdown>
</Blockquote>
@@ -117,7 +118,7 @@ export const getSmolagentsSteps = (ctx: OnboardingComponentsContext): StepDefini
</>
),
},
- getOtelSessionIdStep(ctx, { languages: ['Python'] }),
+ getOtelRequestContextStep(ctx, { languages: ['Python'] }),
]
}