Development
Commands
Section titled “Commands”Building
Section titled “Building”pnpm build # Build all packages (uses Turborepo)pnpm dev # Watch mode for all packagesTesting
Section titled “Testing”# Run all tests (unit + integration)pnpm test
# Package-specific testing (in package directory)pnpm test # Unit tests only (vitest.unit.config.ts)pnpm test:watch # Unit tests in watch modepnpm test:integration # Integration tests (vitest.integration.config.ts)
# Run single test filenpx vitest run src/functional.test.tsImportant: The core autotel package has separate unit and integration test configs:
vitest.unit.config.ts- Excludes*.integration.test.tsfilesvitest.integration.config.ts- Only runs*.integration.test.tsfiles
Linting & Formatting
Section titled “Linting & Formatting”pnpm lint # Lint all packages (ESLint)pnpm format # Format with Prettierpnpm type-check # TypeScript type checkingQuality Check
Section titled “Quality Check”pnpm quality # Runs: build + lint + format + type-check + test + test:integrationRunning Examples
Section titled “Running Examples”# Basic example (demonstrates trace() usage)pnpm --filter @jagreehal/example-basic start
# HTTP server examplepnpm --filter @jagreehal/example-http start
# Cloudflare Workers examplepnpm --filter cloudflare-example devTesting Patterns
Section titled “Testing Patterns”OpenTelemetry Utilities
Section titled “OpenTelemetry Utilities”Autotel re-exports commonly-needed OpenTelemetry utilities in semantically-organized modules. These are already included in autotel's dependencies, so no additional installation is required.
Module Organization:
autotel/exporters — Span exporters for development and testing:
ConsoleSpanExporter— Print spans to console (development debugging, examples)InMemorySpanExporter— Collect spans in memory (testing, assertions)
autotel/processors — Span processors for custom configurations:
SimpleSpanProcessor— Synchronous span processing (testing, immediate export)BatchSpanProcessor— Async batching (production, custom configs)
autotel/testing — High-level testing utilities with assertions:
createTraceCollector()— Auto-configured trace collector with helpersassertTraceCreated(),assertTraceSucceeded(),assertTraceFailed(), etc.- Events and metrics testing utilities
Why re-export? Achieves "one install is all you need" DX without bundle size impact (these are from @opentelemetry/sdk-trace-base, already a dependency).
// Development debugging - see spans in consoleimport { init } from 'autotel';import { ConsoleSpanExporter } from 'autotel/exporters';
init({ service: 'my-app', spanExporters: [new ConsoleSpanExporter()],});
// Low-level testing - collect raw OTel spansimport { init } from 'autotel';import { InMemorySpanExporter } from 'autotel/exporters';import { SimpleSpanProcessor } from 'autotel/processors';
const exporter = new InMemorySpanExporter();init({ service: 'test', spanProcessors: [new SimpleSpanProcessor(exporter)],});
// Run code under testawait myFunction();
// Assert on collected spansconst spans = exporter.getFinishedSpans();expect(spans).toHaveLength(1);Note: For most testing scenarios, prefer autotel's high-level createTraceCollector() utility from autotel/testing which provides assertion helpers and automatic tracer configuration.
Test Harnesses
Section titled “Test Harnesses”Use provided test harnesses for consistent testing:
// Event subscribersimport { SubscriberTestHarness } from 'autotel-subscribers/testing';
const harness = new SubscriberTestHarness(new MySubscriber(config));await harness.testBasicEvent();await harness.testErrorHandling();
// High-level trace testing (recommended)import { createTraceCollector, assertTraceCreated } from 'autotel/testing';
const collector = createTraceCollector();await myService.doSomething();assertTraceCreated(collector, 'myService.doSomething');
// Low-level testing (when you need raw OTel spans)import { InMemorySpanExporter } from 'autotel/exporters';import { SimpleSpanProcessor } from 'autotel/processors';
const exporter = new InMemorySpanExporter();// Use in tests to capture raw spansIntegration Tests
Section titled “Integration Tests”Integration tests require OpenTelemetry SDK setup, so they're isolated in *.integration.test.ts files and run with a separate vitest config.
Common Workflows
Section titled “Common Workflows”Adding a New Event Subscriber
Section titled “Adding a New Event Subscriber”- Create new file in
packages/autotel-subscribers/src/ - Extend
EventSubscriberbase class - Implement
trackEvent(name, attributes?, options?)(and other track* methods as needed). Accept the optional third argumentoptions?: EventTrackingOptions; if present, forwardoptions.autotel(e.g.correlation_id,trace_id,trace_url) into your payload so consumers can correlate events with traces. - Add export to
packages/autotel-subscribers/src/index.ts - Add entry point to
package.jsonexports field - Add tests using
SubscriberTestHarness - Create changeset with
pnpm changeset
Adding a New Instrumentation Integration
Section titled “Adding a New Instrumentation Integration”- Add instrumentation logic to
packages/autotel/src/ - Export from
packages/autotel/src/index.ts - Add entry point to
package.jsonexports if tree-shakeable - Add tests (unit tests in
.test.ts, integration tests in.integration.test.ts) - Update
init.tsif it needs special SDK configuration - Create changeset
Changesets (Version Management)
Section titled “Changesets (Version Management)”pnpm changeset # Create a changeset for your changespnpm version-packages # Bump versions based on changesetspnpm release # Build and publish to npmWhen creating changesets:
- Select affected packages (autotel, autotel-subscribers, autotel-edge, etc.)
- Choose semver bump: patch (bug fixes), minor (new features), major (breaking changes)
- Write clear summary for CHANGELOG
Working with Monorepo Dependencies
Section titled “Working with Monorepo Dependencies”- Use
workspace:*protocol in package.json for internal dependencies - Changes to dependencies automatically trigger rebuilds (Turborepo cache)
- Install new dependency:
pnpm add <package> --filter <workspace-name>(e.g.,pnpm add zod --filter autotel)
Boundaries
Section titled “Boundaries”- Always do: Write tests for new features, use test harnesses, follow existing patterns
- Ask first: Changing test infrastructure, modifying CI/CD configs
- Never do: Skip tests, modify test configs without understanding impact, remove failing tests