Skip to content

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Sep 3, 2025

Which problem is this PR solving?

Note

The shape of the api is open to suggestion.

Add an experimental trace decorator support.

import { decorators } from '@opentelemetry/api/experimental';
import otel from '@opentelemetry/api';

const tracer = otel.trace.getTracer('my-tracer');

class MyTaskRunner {

  @decorators.trace.startActiveSpan(tracer)
  async work() {
    // do async works.
  }

}

The span is automatically ended when the method is finished either synchronously or asynchronously.

Notably, decorator does not support function declarations or function expressions. Only class method declarations are supported.

This requires TypeScript 5.0.

Fixes #3827

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Decorator tests

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

Copy link

codecov bot commented Sep 3, 2025

Codecov Report

❌ Patch coverage is 23.52941% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.61%. Comparing base (90ad17b) to head (5844ea1).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
api/src/experimental/decorators/trace.ts 17.02% 39 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5906      +/-   ##
==========================================
- Coverage   95.06%   94.61%   -0.46%     
==========================================
  Files         307      309       +2     
  Lines        8031     8082      +51     
  Branches     1627     1633       +6     
==========================================
+ Hits         7635     7647      +12     
- Misses        396      435      +39     
Files with missing lines Coverage Δ
api/src/experimental/decorators/index.ts 100.00% <100.00%> (ø)
api/src/experimental/index.ts 100.00% <100.00%> (ø)
api/src/experimental/decorators/trace.ts 17.02% <17.02%> (ø)
🚀 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide typescript decorator to auto instrument functions

1 participant