Skip to main content

Refactor: Enable Mocha Context in OpenTelemetry Instrumentation Tests

·197 words·1 min
Adrien Raimbault
Author
Adrien Raimbault

OpenTelemetry JS is the JavaScript implementation of the OpenTelemetry observability framework, enabling standardized tracing and metrics in distributed systems.

It provides tools to collect and export telemetry data (traces, metrics) from applications to various backends, helping developers monitor and debug distributed systems effectively.


🧩 My Contribution: Refactor Instrumentation Tests
#

This project uses Mocha as the test framework. However, many tests were written using arrow functions, which prevent access to Mocha’s test context (this), limiting some testing capabilities.

I contributed to the OpenTelemetry JS repository by refactoring the instrumentation package tests:
🔗 Pull Request: #5591 – refactor(instrumentation): change tests to allow use of mocha context
🔗 Related Issue: #5572 – Refactor tests to allow use of mocha context
📌 Status: Merged and Closed

🔧 What I Did
#

  • Converted arrow functions in test files to traditional function() expressions.
  • Ensured all tests run successfully with npm run test.

This refactor allows test authors to use Mocha’s this context, improving flexibility and aligning with Mocha best practices.


💡 Why It Matters
#

  • 📚 Improves code consistency and maintainability in the test suite.
  • 🛠️ Helps future contributors write better tests aligned with framework recommendations.

📂 See my other contributions: github.com/Assstra