Skip to content

feat(claude-agent-sdk): add instrumentation for @anthropic-ai/claude-agent-sdk#7974

Closed
mr-lee wants to merge 52 commits into
masterfrom
feat/claude-agent-sdk-integration
Closed

feat(claude-agent-sdk): add instrumentation for @anthropic-ai/claude-agent-sdk#7974
mr-lee wants to merge 52 commits into
masterfrom
feat/claude-agent-sdk-integration

Conversation

@mr-lee

@mr-lee mr-lee commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds support for tracing top-level query, tool, LLM, and subagent calls from the Claude Agent SDK.

This is accomplished by parsing the event stream into tracing-lifecycle events after the fact.

Motivation

Provide support for the Claude Agent SDK package.

@mr-lee
mr-lee requested review from a team as code owners April 10, 2026 13:10
@mr-lee
mr-lee requested review from BridgeAR and removed request for a team April 10, 2026 13:10
@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.55 MB
Deduped: 7.61 MB
No deduping: 7.61 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov

codecov Bot commented Apr 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.66292% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.90%. Comparing base (7bc2032) to head (b421293).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...s/datadog-instrumentations/src/claude-agent-sdk.js 91.86% 10 Missing ⚠️
...trace/src/llmobs/plugins/claude-agent-sdk/index.js 95.67% 7 Missing ⚠️
...ckages/datadog-plugin-claude-agent-sdk/src/util.js 83.33% 1 Missing ⚠️
packages/dd-trace/src/plugins/index.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7974      +/-   ##
==========================================
- Coverage   93.64%   92.90%   -0.74%     
==========================================
  Files         898      904       +6     
  Lines       52365    52720     +355     
  Branches    12324    12415      +91     
==========================================
- Hits        49038    48982      -56     
- Misses       3327     3738     +411     
Flag Coverage Δ
aiguard 34.88% <50.00%> (-0.07%) ⬇️
aiguard-integration 41.97% <50.00%> (+<0.01%) ⬆️
apm-bucket-0 35.16% <50.00%> (+0.23%) ⬆️
apm-bucket-1 40.51% <50.00%> (-0.07%) ⬇️
apm-bucket-2 37.51% <50.00%> (-0.07%) ⬇️
apm-capabilities-tracing 48.59% <16.85%> (-0.30%) ⬇️
apm-integrations-aerospike 33.13% <50.00%> (-0.07%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.04% <50.00%> (-0.07%) ⬇️
apm-integrations-couchbase 33.25% <50.00%> (-0.24%) ⬇️
apm-integrations-http 42.06% <50.00%> (-0.07%) ⬇️
apm-integrations-kafkajs 40.26% <50.00%> (-0.12%) ⬇️
apm-integrations-next 29.63% <50.00%> (-0.07%) ⬇️
apm-integrations-prisma 35.19% <50.00%> (-0.07%) ⬇️
apm-integrations-tedious 34.05% <50.00%> (-0.07%) ⬇️
appsec 57.90% <50.00%> (+0.02%) ⬆️
appsec-express_fastify_graphql 53.83% <50.00%> (-0.10%) ⬇️
appsec-integration 35.59% <12.40%> (-0.10%) ⬇️
appsec-kafka_ldapjs_lodash 43.75% <50.00%> (-0.06%) ⬇️
appsec-mongodb-core_mongoose_mysql 48.91% <50.00%> (-0.06%) ⬇️
appsec-next 28.13% <50.00%> (-0.05%) ⬇️
appsec-node-serialize_passport_postgres 48.13% <50.00%> (-0.06%) ⬇️
appsec-sourcing_stripe_template 45.64% <50.00%> (-0.06%) ⬇️
debugger 44.64% <50.00%> (+<0.01%) ⬆️
instrumentations-bucket-0 28.18% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-1 37.57% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-10 40.52% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-11 27.97% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-12 28.80% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-13 27.80% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-2 30.37% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-3 36.07% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-4 28.58% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-5 36.43% <50.00%> (-0.06%) ⬇️
instrumentations-bucket-6 38.43% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-7 36.16% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-8 37.11% <50.00%> (-0.07%) ⬇️
instrumentations-bucket-9 39.62% <50.00%> (-0.07%) ⬇️
instrumentations-instrumentation-couchbase 46.52% <100.00%> (+0.03%) ⬆️
instrumentations-integration-esbuild 24.46% <12.40%> (-0.06%) ⬇️
llmobs-ai_anthropic_bedrock 39.68% <50.00%> (-0.06%) ⬇️
llmobs-bucket-1 37.71% <94.66%> (?)
llmobs-google-genai_langchain_vertex-ai ?
llmobs-openai 39.75% <50.00%> (-0.07%) ⬇️
llmobs-sdk 43.59% <50.00%> (-0.08%) ⬇️
llmobs-vertex-ai 35.88% <50.00%> (?)
master-coverage 92.90% <94.66%> (?)
openfeature 37.94% <50.00%> (+<0.01%) ⬆️
openfeature-unit 50.47% <ø> (ø)
platform-core_esbuild_instrumentations-misc 22.91% <12.40%> (-0.05%) ⬇️
platform-integration 47.58% <50.00%> (-0.02%) ⬇️
platform-shimmer_unit-guardrails_webpack 18.44% <12.40%> (-0.04%) ⬇️
plugins-bucket-0 36.53% <50.00%> (-0.06%) ⬇️
plugins-bucket-1 39.79% <50.00%> (+<0.01%) ⬆️
plugins-bucket-11 38.63% <50.00%> (-0.07%) ⬇️
plugins-bucket-17 39.22% <50.00%> (-0.07%) ⬇️
plugins-bucket-18 42.18% <50.00%> (-0.06%) ⬇️
plugins-bucket-19 ?
plugins-bucket-20 ?
plugins-bucket-4 ?
plugins-bullmq_cassandra_cookie 39.93% <50.00%> (-0.07%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api ?
plugins-fetch_fs_generic-pool 36.22% <50.00%> (-0.07%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.09% <50.00%> (-0.07%) ⬇️
plugins-hapi_hono_ioredis 37.95% <50.00%> (-0.07%) ⬇️
plugins-jest_knex_langgraph 32.62% <50.00%> (-0.07%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.87% <50.00%> (-0.07%) ⬇️
plugins-lodash_mariadb_memcached 35.18% <50.00%> (-0.07%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.47% <50.00%> (-0.07%) ⬇️
plugins-multer_mysql_mysql2 35.16% <50.00%> (-0.07%) ⬇️
plugins-nats_node-serialize_opensearch 37.32% <50.00%> (-0.07%) ⬇️
plugins-passport-http_pino_postgres 35.54% <50.00%> (-0.07%) ⬇️
plugins-process_pug_redis 34.27% <50.00%> (-0.07%) ⬇️
plugins-undici_url_valkey 36.04% <50.00%> (-0.07%) ⬇️
plugins-vm_winston_ws 37.72% <50.00%> (-0.07%) ⬇️
profiling 43.81% <50.00%> (-0.07%) ⬇️
serverless-aws-sdk-aws-sdk 33.33% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-bedrockruntime 32.20% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-client 37.20% <100.00%> (+0.03%) ⬆️
serverless-aws-sdk-dynamodb 34.20% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-eventbridge 27.37% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-kinesis 37.55% <50.00%> (-0.07%) ⬇️
serverless-aws-sdk-lambda 34.64% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-s3 32.64% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.66% <50.00%> (-0.07%) ⬇️
serverless-aws-sdk-sns 38.41% <50.00%> (-0.18%) ⬇️
serverless-aws-sdk-sqs 38.15% <50.00%> (-0.07%) ⬇️
serverless-aws-sdk-stepfunctions 33.23% <50.00%> (-0.06%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.64% <50.00%> (+<0.01%) ⬆️
serverless-lambda 34.33% <16.66%> (-0.10%) ⬇️
test-optimization-cucumber 52.54% <50.00%> (+0.11%) ⬆️
test-optimization-cypress 49.63% <50.00%> (+0.06%) ⬆️
test-optimization-jest 55.57% <50.00%> (+0.04%) ⬆️
test-optimization-mocha 53.61% <50.00%> (+0.07%) ⬆️
test-optimization-playwright-playwright-atr 43.53% <50.00%> (+0.08%) ⬆️
test-optimization-playwright-playwright-efd 43.82% <50.00%> (+0.08%) ⬆️
test-optimization-playwright-playwright-final-status 43.94% <50.00%> (+0.08%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.36% <50.00%> (+<0.01%) ⬆️
test-optimization-playwright-playwright-reporting 43.47% <50.00%> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-management 44.93% <50.00%> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-span 44.72% <50.00%> (+0.21%) ⬆️
test-optimization-selenium 45.44% <50.00%> (+0.06%) ⬆️
test-optimization-testopt 46.82% <50.00%> (+0.08%) ⬆️
test-optimization-vitest 52.73% <50.00%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Apr 10, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 80.62%
Overall Coverage: 87.81% (-0.05%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b421293 | Docs | Datadog PR Page | Give us feedback!

@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch 2 times, most recently from 33b112c to 68c716f Compare April 10, 2026 13:40
@sabrenner sabrenner self-assigned this Apr 10, 2026
@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch 2 times, most recently from 52e6727 to e497246 Compare April 10, 2026 17:12
@mr-lee
mr-lee requested a review from a team as a code owner April 10, 2026 17:12
@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch from e497246 to 045d54a Compare April 10, 2026 17:28
@pr-commenter

pr-commenter Bot commented Apr 10, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-02 20:41:39

Comparing candidate commit b421293 in PR branch feat/claude-agent-sdk-integration with baseline commit 7bc2032 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2255 metrics, 31 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-181918.749µs; +182592.382µs] or [-6.921%; +6.947%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-212.408ms; +204.664ms] or [-8.473%; +8.164%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-152.842ms; +158.562ms] or [-5.318%; +5.517%]

scenario:appsec-control-20

  • unstable execution_time [-81.799ms; +133.333ms] or [-5.094%; +8.303%]

scenario:appsec-control-24

  • unstable execution_time [-105748.205µs; +107167.672µs] or [-8.700%; +8.817%]

scenario:appsec-control-26

  • unstable execution_time [-120.031ms; +107.654ms] or [-10.016%; +8.983%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-2965.657ms; +1917.495ms] or [-31.896%; +20.623%]
  • unstable execution_time [-3029.994ms; +1976.213ms] or [-30.342%; +19.790%]
  • unstable instructions [-25.5G instructions; +16.5G instructions] or [-33.375%; +21.682%]
  • unstable max_rss_usage [-12.077MB; +8.673MB] or [-7.489%; +5.378%]
  • unstable throughput [-559.239op/s; +880.916op/s] or [-16.640%; +26.212%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-2805.609ms; +2544.068ms] or [-29.997%; +27.200%]
  • unstable execution_time [-2851.905ms; +2575.962ms] or [-28.442%; +25.690%]
  • unstable instructions [-23535.2M instructions; +21838.9M instructions] or [-30.648%; +28.439%]
  • unstable max_rss_usage [-11385.014KB; +10985.814KB] or [-7.129%; +6.879%]
  • unstable throughput [-678.295op/s; +702.359op/s] or [-20.197%; +20.913%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-2016.023ms; +3192.283ms] or [-21.576%; +34.165%]
  • unstable execution_time [-2057.237ms; +3241.378ms] or [-20.523%; +32.335%]
  • unstable instructions [-17.9G instructions; +28.6G instructions] or [-23.016%; +36.739%]
  • unstable max_rss_usage [-6.567MB; +10.645MB] or [-4.138%; +6.708%]
  • unstable throughput [-715.383op/s; +457.181op/s] or [-21.865%; +13.973%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-2855.692ms; +2909.417ms] or [-28.699%; +29.239%]
  • unstable execution_time [-2888.710ms; +2928.353ms] or [-27.148%; +27.521%]
  • unstable instructions [-25456.1M instructions; +26071.3M instructions] or [-30.565%; +31.304%]
  • unstable max_rss_usage [-9462.619KB; +9076.219KB] or [-5.876%; +5.636%]
  • unstable throughput [-648.907op/s; +627.050op/s] or [-20.644%; +19.948%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-333.483ms; +409.876ms] or [-6.787%; +8.342%]
  • unstable execution_time [-332.277ms; +408.373ms] or [-6.659%; +8.184%]
  • unstable throughput [-140211.171op/s; +115804.347op/s] or [-8.324%; +6.875%]

scenario:plugin-graphql-long-with-depth-off-20

  • unstable max_rss_usage [-8366.471KB; +7937.328KB] or [-6.521%; +6.187%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-5422.776KB; +5640.776KB] or [-6.673%; +6.941%]

@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch 2 times, most recently from 8ed7a6b to 04accb7 Compare April 10, 2026 18:42
@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch from 04accb7 to e98f416 Compare April 13, 2026 16:28

@sabrenner sabrenner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high-level comments, two main callouts:

  1. we should still be able to use orchestrion, even when doing argument mutations. orchestrion is great for tracing the top-level things like query directly with lifecycle events, but otherwise we can intercept arguments and patch them there. ideally, we could also patch the code where hooks are called and do a tracing channel on that function.
  2. we should be able to actually test against the library vs using hooks & mocking calls to the library. i was able to require it in a CJS file, and even if it doesn't work here, we can write some tests in our integration-test suite to run ESM files.
  3. looks like there are a couple of debugger changes in this PR that are unrelated and are probs just from a bad rebase. for some reason i couldnt comment on them directly

i think these points will change a decent chunk of the code, so i'll do a further in-depth review after!

Comment thread benchmark/sirun/plugin-claude-agent-sdk/index.js Outdated
Comment thread packages/datadog-instrumentations/src/claude-agent-sdk.js Outdated
Comment thread packages/datadog-instrumentations/src/claude-agent-sdk.js Outdated
Comment thread packages/datadog-plugin-claude-agent-sdk/src/tracing.js Outdated
Comment thread packages/datadog-plugin-claude-agent-sdk/test/index.spec.js
Comment thread packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js Outdated
Comment thread packages/dd-trace/test/llmobs/plugins/claude-agent-sdk/index.spec.js Outdated
@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch 4 times, most recently from 975e1b2 to 9fb8c74 Compare April 14, 2026 16:28

const assert = require('node:assert')
const { describe, before, after, it } = require('mocha')
const { tracingChannel, channel } = require('dc-polyfill')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried setting ANTHROPIC_BASE_URL=http://127.0.0.1:19126 and running query() — the subprocess spawns and returns real messages, but zero HTTP requests hit the proxy. The CLI binary (cli.js) reads ANTHROPIC_BASE_URL but has a host validation (function cH) that checks if the host is api.anthropic.com. Non-standard hosts get filtered. How did you get it working locally? Were you using the bridge entry point or the default query() path?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also tried setting CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST: true and see if that helps, that's what i also had to include locally as otherwise i ran into what you're describing


const assert = require('node:assert')
const { describe, before, after, it } = require('mocha')
const { tracingChannel, channel } = require('dc-polyfill')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That worked! CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=true makes the subprocess send HTTP through the configured ANTHROPIC_BASE_URL. Proxy captured POST /v1/messages?beta=true requests.

One issue for cassette recording: the CLI uses Vault OIDC auth (not raw ANTHROPIC_API_KEY), so the requests 401 when proxied. Would be great to pair on getting a successful recording for the cassette — do you have a working cassette from your local testing?

@mr-lee
mr-lee force-pushed the feat/claude-agent-sdk-integration branch from 9fb8c74 to f6d9ca1 Compare April 15, 2026 18:14
Comment thread docker-compose.yml
- VCR_PROVIDER_MAP=claude-agent-sdk=https://api.anthropic.com
- VCR_JSON_BODY_NORMALIZERS=metadata.user_id,output_config.effort
- >-
VCR_BODY_REGEX_NORMALIZERS=agentId: [a-f0-9]+,SendMessage with to: '[a-f0-9]+',<usage>[\s\S]*?</usage>,"events":\[\{"event_type":"ClaudeCodeInternalEvent"[^\]]*\],cc_version=[^;]+,cch=[^;]+,<system-reminder>[\s\S]*?</system-reminder>,<env>[\s\S]*?</env>,(?<="input":\{"description":")[^"]*,(?:You are an agent for Claude Code|Write the title|Report the result concisely\.|Async agent launched successfully)(?:\\.|[^"\\])*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of weird normalization had to happen between the linux GHA runners, local macos development, etc., but these normalizations on things that are non-query specific seem to do the trick. this might be finicky for versions going forward, but work here

@sabrenner

Copy link
Copy Markdown
Collaborator

@codex review

@mr-lee

mr-lee commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

was there a strong reason to swap away from hook-based instrumentation?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff1240fee8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/datadog-instrumentations/src/claude-agent-sdk.js
Comment thread packages/datadog-instrumentations/src/claude-agent-sdk.js Outdated
Comment thread index.d.ts
@sabrenner

Copy link
Copy Markdown
Collaborator

was there a strong reason to swap away from hook-based instrumentation?

we would not get LLM spans while using hooks, and parentage was still very finicky. Parsing the event stream seems to be more stable to me

@mr-lee

mr-lee commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

we would not get LLM spans while using hooks, and parentage was still very finicky. Parsing the event stream seems to be more stable to me

This makes sense for the LLM spans - but also - the hooks are a direct ancestor to the event stream, in a way. IMO it's a more stable surface to instrument to get reliable span creation than the event stream in isolation. Perhaps consider a joint approach?

@sabrenner

Copy link
Copy Markdown
Collaborator

Perhaps consider a joint approach?

i had thought of that, but parentage gets really tricky and i'd rather not be storing contexts and re-activating them when we can "reconstruct" the lifecycle events with tracing channels and make it a bit cleaner. this is sorta similar to our approach with tracing the python version as well.

@mr-lee

mr-lee commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

i had thought of that, but parentage gets really tricky and i'd rather not be storing contexts and re-activating them when we can "reconstruct" the lifecycle events with tracing channels and make it a bit cleaner. this is sorta similar to our approach with tracing the python version as well.

Wait - does this need to be stored in memory? My argument is to have this be the trigger (e.g. the "Stop" hook) because that's the cleanest injection point. As and when progressive tracing (i.e. be able to publish incomplete traces) becomes a requirement - additional hook points can be included.

@sabrenner

Copy link
Copy Markdown
Collaborator

superseded by #9202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants