Skip to content

test(ai): add preserve OpenTelemetry span receiver test#9309

Open
crysmags wants to merge 7 commits into
masterfrom
apm-ai-toolkit/execute/vercel-ai/20260711-002154
Open

test(ai): add preserve OpenTelemetry span receiver test#9309
crysmags wants to merge 7 commits into
masterfrom
apm-ai-toolkit/execute/vercel-ai/20260711-002154

Conversation

@crysmags

@crysmags crysmags commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Builds on #9152's fix for #9151 by keeping the delegating OTel span wrapper private and making its forwarding contract exact. Every Span method runs against the real underlying span with the caller's original arguments, while chainable methods return the per-invocation wrapper and end, setAttributes, and recordException continue publishing the existing diagnostic-channel events.

The wrapper remains fresh per invocation, so the AI SDK's shared no-op span is not mutated and each publication keeps the correct invocation context.

Why is this stronger than the implementation on master?

The implementation on master fixes the private-field receiver bug, but manually restates each method signature. This version uses apply(span, arguments) so optional arguments, return behavior, and future compatible Span signature changes are forwarded without drift. The helper stays local to the instrumentation and is not exported for tests.

Test coverage

  • Exercises the AI SDK 6 error path with a real dd-trace OTel TracerProvider, asserting that the original model error is preserved and the emitted span records that error.
  • Exercises every OTel Span method through the public AI SDK instrumentation path, asserting the underlying receiver, exact arguments, chainability, and return behavior.
  • Retains the existing private-field regression across supported AI SDK 4, 5, and 6 fixtures.

Verification

  • Focused error and complete-delegation regressions: 8 passing across AI SDK 6.0.0 and 6.0.227 with the minimum and latest compatible OpenAI providers.
  • Retained cross-version private-field regression: 10 passing across AI SDK 4, 5, and 6 fixtures.
  • Focused ESLint: passing.
  • git diff --check: passing.

@dd-octo-sts

dd-octo-sts Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 7.52 MB
Deduped: 8.18 MB
No deduping: 8.18 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.2 | 124.41 kB | 440.65 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

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jul 13, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.44% (+0.00%)

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

@pr-commenter

pr-commenter Bot commented Jul 13, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-22 19:00:09

Comparing candidate commit 1cb6374 in PR branch apm-ai-toolkit/execute/vercel-ai/20260711-002154 with baseline commit fbd459a in branch master.

📊 Benchmarking dashboard

Found 1 performance improvements and 0 performance regressions! Performance is the same for 2311 metrics, 46 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 ----------------------------------'

scenario:encoders-0.4-events-native-20

  • 🟩 max_rss_usage [-11.770MB; -3.107MB] or [-8.195%; -2.163%]

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 [-214534.905µs; +213676.239µs] or [-8.021%; +7.988%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-236.206ms; +233.663ms] or [-9.249%; +9.149%]

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

  • unstable execution_time [-191546.745µs; +190051.645µs] or [-6.484%; +6.434%]

scenario:appsec-control-20

  • unstable execution_time [-143.334ms; +107.850ms] or [-8.740%; +6.576%]

scenario:appsec-control-24

  • unstable execution_time [-114155.120µs; +113745.487µs] or [-9.193%; +9.160%]

scenario:appsec-control-26

  • unstable execution_time [-126.773ms; +124.666ms] or [-10.234%; +10.064%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-11.458ms; +16.359ms] or [-4.547%; +6.492%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-15.375ms; +12.779ms] or [-6.037%; +5.017%]

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

  • unstable cpu_user_time [-1991.210ms; +3218.395ms] or [-24.031%; +38.842%]
  • unstable execution_time [-1990.484ms; +3240.609ms] or [-22.104%; +35.987%]
  • unstable instructions [-17.0G instructions; +27.3G instructions] or [-25.181%; +40.315%]
  • unstable max_rss_usage [-8.826MB; +12.992MB] or [-5.613%; +8.263%]
  • unstable throughput [-862.256op/s; +521.900op/s] or [-23.563%; +14.262%]

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

  • unstable cpu_user_time [-1735.700ms; +572.483ms] or [-20.912%; +6.898%]
  • unstable execution_time [-1740.609ms; +579.273ms] or [-19.287%; +6.419%]
  • unstable instructions [-14.9G instructions; +4.9G instructions] or [-22.046%; +7.230%]
  • unstable throughput [-158.845op/s; +464.162op/s] or [-4.354%; +12.724%]

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

  • unstable cpu_user_time [-3698.097ms; +3666.474ms] or [-35.841%; +35.535%]
  • unstable execution_time [-3669.013ms; +3653.254ms] or [-33.162%; +33.020%]
  • unstable instructions [-32504.6M instructions; +32546.0M instructions] or [-37.610%; +37.658%]
  • unstable max_rss_usage [-11304.261KB; +12005.061KB] or [-7.007%; +7.441%]
  • unstable throughput [-713.244op/s; +720.539op/s] or [-23.230%; +23.468%]

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

  • unstable cpu_user_time [-2812.813ms; +3980.029ms] or [-29.627%; +41.921%]
  • unstable execution_time [-2773.917ms; +4008.244ms] or [-27.178%; +39.271%]
  • unstable instructions [-23.6G instructions; +33.7G instructions] or [-30.325%; +43.339%]
  • unstable max_rss_usage [-11.840MB; +16.725MB] or [-7.305%; +10.319%]
  • unstable throughput [-1059.245op/s; +730.307op/s] or [-31.704%; +21.859%]

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

  • unstable cpu_user_time [-2634.881ms; +4200.721ms] or [-27.569%; +43.952%]
  • unstable execution_time [-2621.863ms; +4196.482ms] or [-25.479%; +40.782%]
  • unstable instructions [-23.3G instructions; +37.1G instructions] or [-29.271%; +46.537%]
  • unstable max_rss_usage [-8.546MB; +13.275MB] or [-5.355%; +8.319%]
  • unstable throughput [-820.429op/s; +510.676op/s] or [-25.468%; +15.852%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-363.713ms; +297.759ms] or [-7.332%; +6.003%]
  • unstable execution_time [-357.064ms; +300.174ms] or [-7.093%; +5.963%]
  • unstable throughput [-90063.269op/s; +133594.656op/s] or [-5.398%; +8.007%]

scenario:plugin-aws-sdk-lambda-inject-with-context-24

  • unstable cpu_user_time [-152.726ms; +301.780ms] or [-3.985%; +7.875%]
  • unstable execution_time [-151.164ms; +300.125ms] or [-3.919%; +7.781%]
  • unstable throughput [-38057.775op/s; +19312.077op/s] or [-7.291%; +3.700%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-26

  • unstable cpu_usage_percentage [-6.040%; +5.014%]

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

  • unstable max_rss_usage [-26.382MB; +39.173MB] or [-6.595%; +9.792%]

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

  • unstable max_rss_usage [-7347.519KB; +6593.233KB] or [-5.623%; +5.046%]

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

  • unstable max_rss_usage [-18.381MB; +28.863MB] or [-8.682%; +13.634%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable cpu_user_time [-594.435ms; +606.042ms] or [-5.152%; +5.253%]
  • unstable execution_time [-604.998ms; +609.415ms] or [-5.139%; +5.177%]
  • unstable throughput [-3.567op/s; +3.529op/s] or [-5.218%; +5.163%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-5438.125KB; +5726.458KB] or [-6.711%; +7.067%]

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.79%. Comparing base (fbd459a) to head (1cb6374).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9309      +/-   ##
==========================================
- Coverage   98.44%   96.79%   -1.66%     
==========================================
  Files         943      941       -2     
  Lines      127310   127270      -40     
  Branches    10824    10453     -371     
==========================================
- Hits       125335   123190    -2145     
- Misses       1975     4080    +2105     
Flag Coverage Δ
aiguard 57.87% <ø> (-0.10%) ⬇️
aiguard-integration 56.19% <68.85%> (-0.01%) ⬇️
apm-bucket-0 57.74% <ø> (-0.03%) ⬇️
apm-bucket-1 64.03% <ø> (-0.03%) ⬇️
apm-bucket-2 62.79% <ø> (-0.03%) ⬇️
apm-bucket-3 60.16% <ø> (-0.03%) ⬇️
apm-capabilities-tracing 64.49% <ø> (ø)
apm-integrations-aerospike 56.74% <ø> (-0.03%) ⬇️
apm-integrations-confluentinc-kafka-javascript 61.68% <ø> (-0.03%) ⬇️
apm-integrations-couchbase 57.18% <ø> (-0.03%) ⬇️
apm-integrations-http 62.81% <ø> (-0.03%) ⬇️
apm-integrations-kafkajs 62.23% <ø> (-0.03%) ⬇️
apm-integrations-next 59.28% <ø> (-0.03%) ⬇️
apm-integrations-prisma 58.75% <ø> (-0.03%) ⬇️
appsec 72.94% <ø> (-0.05%) ⬇️
appsec-express_fastify_graphql 70.44% <ø> (-0.02%) ⬇️
appsec-integration 51.39% <19.67%> (-0.01%) ⬇️
appsec-kafka_ldapjs_lodash 64.02% <ø> (-0.03%) ⬇️
appsec-mongodb-core_mongoose_mysql 67.74% <ø> (-0.02%) ⬇️
appsec-next 57.58% <ø> (-0.02%) ⬇️
appsec-node-serialize_passport_postgres 67.41% <ø> (-0.02%) ⬇️
appsec-sourcing_stripe_template 65.75% <ø> (-0.02%) ⬇️
debugger 64.93% <ø> (-0.04%) ⬇️
instrumentations-bucket-0 51.68% <19.67%> (-0.03%) ⬇️
instrumentations-bucket-1 60.28% <ø> (-0.03%) ⬇️
instrumentations-bucket-10 61.84% <ø> (-0.03%) ⬇️
instrumentations-bucket-11 56.76% <ø> (-0.03%) ⬇️
instrumentations-bucket-12 52.06% <ø> (-0.03%) ⬇️
instrumentations-bucket-13 52.08% <ø> (-0.03%) ⬇️
instrumentations-bucket-2 53.38% <ø> (-0.03%) ⬇️
instrumentations-bucket-3 53.67% <ø> (-0.03%) ⬇️
instrumentations-bucket-4 59.27% <ø> (-0.03%) ⬇️
instrumentations-bucket-5 50.09% <ø> (-0.03%) ⬇️
instrumentations-bucket-6 60.99% <ø> (-0.03%) ⬇️
instrumentations-bucket-7 58.42% <ø> (-0.03%) ⬇️
instrumentations-bucket-8 59.51% <ø> (-0.03%) ⬇️
instrumentations-bucket-9 52.07% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-couchbase 51.13% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-zlib 51.72% <ø> (-0.03%) ⬇️
instrumentations-integration-esbuild 34.11% <19.67%> (+<0.01%) ⬆️
llmobs-ai_anthropic_bedrock 63.24% <100.00%> (+0.38%) ⬆️
llmobs-bucket-1 61.59% <ø> (-0.02%) ⬇️
llmobs-openai 62.75% <ø> (-0.03%) ⬇️
llmobs-sdk 66.25% <ø> (-0.03%) ⬇️
llmobs-vertex-ai 59.25% <ø> (-0.04%) ⬇️
master-coverage 96.79% <100.00%> (?)
openfeature 56.20% <ø> (ø)
openfeature-unit 53.50% <ø> (-0.03%) ⬇️
platform-core_esbuild_instrumentations-misc 40.43% <19.67%> (-0.02%) ⬇️
platform-integration 61.50% <ø> (ø)
platform-shimmer_unit-guardrails_webpack 39.13% <19.67%> (-0.02%) ⬇️
plugins-bucket-0 57.14% <ø> (-0.03%) ⬇️
plugins-bucket-1 54.44% <ø> (ø)
plugins-bucket-11 62.37% <ø> (-0.03%) ⬇️
plugins-bucket-18 62.06% <ø> (-0.03%) ⬇️
plugins-bucket-19 60.16% <ø> (-0.03%) ⬇️
plugins-bucket-20 62.17% <ø> (-0.03%) ⬇️
plugins-bucket-4 58.69% <ø> (-0.03%) ⬇️
plugins-bullmq_cassandra_cookie 61.86% <ø> (-0.03%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 56.83% <ø> (-0.03%) ⬇️
plugins-fetch_fs_generic-pool 58.88% <ø> (-0.03%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 64.79% <ø> (-0.03%) ⬇️
plugins-hapi_hono_ioredis 60.33% <ø> (-0.03%) ⬇️
plugins-jest_knex_langgraph 55.70% <ø> (-0.03%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 58.61% <ø> (-0.03%) ⬇️
plugins-lodash_mariadb_memcached 58.11% <ø> (-0.03%) ⬇️
plugins-moleculer_mongodb_mongodb-core 62.02% <ø> (-0.03%) ⬇️
plugins-mongoose_multer_mysql 59.12% <ø> (-0.03%) ⬇️
plugins-mysql2_nats_node-serialize 60.82% <ø> (-0.03%) ⬇️
plugins-opensearch_passport-http_pino 59.65% <ø> (-0.03%) ⬇️
plugins-postgres_process_pug 58.38% <ø> (-0.03%) ⬇️
plugins-redis_router_sequelize 62.15% <ø> (-0.03%) ⬇️
plugins-test-and-upstream-rhea_undici_url 61.73% <ø> (-0.03%) ⬇️
plugins-valkey_vm_winston 58.11% <ø> (-0.03%) ⬇️
plugins-ws 59.68% <ø> (-0.03%) ⬇️
profiling 62.25% <ø> (-0.03%) ⬇️
serverless-aws-sdk-aws-sdk 55.16% <ø> (-0.02%) ⬇️
serverless-aws-sdk-bedrockruntime 54.85% <ø> (-0.03%) ⬇️
serverless-aws-sdk-client 56.53% <ø> (-0.03%) ⬇️
serverless-aws-sdk-dynamodb 55.77% <ø> (-0.02%) ⬇️
serverless-aws-sdk-eventbridge 49.47% <ø> (-0.03%) ⬇️
serverless-aws-sdk-kinesis 59.44% <ø> (-0.03%) ⬇️
serverless-aws-sdk-lambda 57.49% <ø> (-0.03%) ⬇️
serverless-aws-sdk-s3 55.70% <ø> (-0.03%) ⬇️
serverless-aws-sdk-serverless-peer-service 59.84% <ø> (-0.03%) ⬇️
serverless-aws-sdk-sns 60.23% <ø> (-0.03%) ⬇️
serverless-aws-sdk-sqs 60.67% <ø> (-0.03%) ⬇️
serverless-aws-sdk-stepfunctions 55.68% <ø> (-0.03%) ⬇️
serverless-aws-sdk-util 51.58% <ø> (-0.03%) ⬇️
serverless-bucket-0 54.34% <ø> (ø)
serverless-bucket-1 59.36% <ø> (-0.03%) ⬇️
test-optimization-cucumber ?
test-optimization-cypress 65.73% <ø> (+<0.01%) ⬆️
test-optimization-jest ?
test-optimization-mocha 73.50% <ø> (+0.03%) ⬆️
test-optimization-playwright-playwright-atr 60.38% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-efd 60.57% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-final-status 60.54% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-impacted-tests 60.27% <ø> (+0.14%) ⬆️
test-optimization-playwright-playwright-reporting 61.55% <ø> (-0.13%) ⬇️
test-optimization-playwright-playwright-test-management 61.08% <ø> (-0.13%) ⬇️
test-optimization-playwright-playwright-test-span 60.49% <ø> (-0.09%) ⬇️
test-optimization-selenium 60.02% <ø> (-0.17%) ⬇️
test-optimization-testopt 58.47% <ø> (+0.08%) ⬆️
test-optimization-vitest 70.30% <ø> (+<0.01%) ⬆️

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.

@crysmags
crysmags marked this pull request as ready for review July 14, 2026 21:30
@crysmags
crysmags requested review from a team as code owners July 14, 2026 21:30
@crysmags
crysmags requested review from wconti27 and removed request for a team July 14, 2026 21:30
@wconti27 wconti27 added the apm-integration-toolkit PR Generated by APM AI Integration Toolkit label Jul 14, 2026
Comment on lines +119 to +135
/**
* Builds a per-invocation delegating wrapper around an OTel span.
*
* Every method forwards to the underlying `span` with `this === span` (via
* `.apply(span, arguments)`), so any private-field access inside the span
* implementation lands on the real instance. This is why we cannot use
* `Object.create(span)` or `new Proxy(span, …)` here: both fail a private-field
* brand check (e.g. dd-trace's own OTel-bridge span stores status in a private
* `#statusCode` field, so a prototype clone's `setStatus()` throws
* "Cannot read private member #statusCode").
*
* A fresh wrapper per `startActiveSpan` callback also preserves the behavior the
* shared AI SDK `noopSpan` needs: the publishing methods close over this call's
* `ctx` without mutating the reused singleton.
*
* Only `end`, `setAttributes`, and `recordException` publish to the diagnostic
* channels before delegating; the rest are straight pass-throughs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: verbose comment can be cleaned up, not a blocker

@crysmags crysmags Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Cleaned this up in 035715d. The comment now keeps just the two constraints that are easy to miss: preserving the original method receiver and avoiding mutation of the shared no-op span.

/**
* Wraps an OTel span without changing its method receivers.
*
* OTel spans may use private fields, so methods must run against the original
* span. A per-invocation wrapper also preserves `ctx` without mutating the AI
* SDK's shared no-op span.
*
* @param {import('@opentelemetry/api').Span} span

})

return originalCb.call(this, freshSpan)
return originalCb.call(this, createDelegatingSpan(span, ctx))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code makes me feel like we should have an Otel to DD reusable helper (could be a followup), considering more and more libs are using the OTel API

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed this could be worth extracting once another integration needs the same behavior. I kept it local for now because the diagnostic-channel publications and per-call ctx are Vercel AI-specific; with only one consumer, a shared helper would make that integration-specific contract look more general than it is.

wconti27
wconti27 previously approved these changes Jul 14, 2026

@wconti27 wconti27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left some nit comments, otherwise LGTM

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code change itself seems good, just the tests need to be reworked to be more realistic

})

module.exports = { wrapModelWithLifecycle }
module.exports = { wrapModelWithLifecycle, createDelegatingSpan }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not export createDelegatingSpan. That is only used in tests and that means we actually do not test things as a user would be able to reach the code. Thus, the tests are not really well testing the surface.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@BridgeAR removed the test-only export and the direct createDelegatingSpan test suite. The regression now reaches the behavior only through ai.generateText with the real dd-trace OTel provider, and verifies both the original model error and the emitted error span:

it('preserves the original model error with a dd-trace OTel tracer', async () => {
const originalError = new Error('original model error')
const model = {
specificationVersion: 'v3',
provider: 'test',
modelId: 'test',
supportedUrls: {},
doGenerate () { return Promise.reject(originalError) },
doStream () { return Promise.reject(originalError) },
}
const TracerProvider = require('../../dd-trace/src/opentelemetry/tracer_provider')
const otelTracer = new TracerProvider().getTracer('ai')
const checkTraces = agent.assertSomeTraces(traces => {
assertObjectContains(traces[0][0], {
name: 'ai.generateText.doGenerate',
error: 1,
meta: {
'error.message': originalError.message,
},
})
})
await assert.rejects(
ai.generateText({
model,
prompt: 'trigger an error',
maxRetries: 0,
experimental_telemetry: { isEnabled: true, tracer: otelTracer },
}),
error => error === originalError
)
await checkTraces
})

const otelTracer = new TracerProvider().getTracer('ai')
const checkTraces = agent.assertSomeTraces(traces => {
assertObjectContains(traces[0][0], {
name: 'ai.generateText.doGenerate',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that name depends on the version, no?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@BridgeAR yea, it does. I removed the name assertion and now find the span by the original error metadata, then verify it is marked as an error. This passes against both 6.0.0 and master’s resolved 6.0.227 fixture:

const TracerProvider = require('../../dd-trace/src/opentelemetry/tracer_provider')
const otelTracer = new TracerProvider().getTracer('ai')
const checkTraces = agent.assertSomeTraces(traces => {
const errorSpan = traces.flat().find(span => span.meta?.['error.message'] === originalError.message)
assert.ok(errorSpan, 'Expected a span for the original model error')
assert.strictEqual(errorSpan.error, 1)
})
await assert.rejects(
ai.generateText({
model,
prompt: 'trigger an error',
maxRetries: 0,
experimental_telemetry: { isEnabled: true, tracer: otelTracer },
}),
error => error === originalError
)
await checkTraces

@BridgeAR BridgeAR changed the title fix(ai): preserve OpenTelemetry span receiver test(ai): add preserve OpenTelemetry span receiver test Jul 16, 2026
@sabrenner

Copy link
Copy Markdown
Collaborator

i think this change merged last week might address this issue? #9152

@crysmags
crysmags force-pushed the apm-ai-toolkit/execute/vercel-ai/20260711-002154 branch from 5b3ab17 to 1cb6374 Compare July 22, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apm-integration-toolkit PR Generated by APM AI Integration Toolkit semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants