Skip to content

Conversation

nicknisi
Copy link
Member

@nicknisi nicknisi commented Jun 12, 2025

Summary

Add runtime and version detection to the WorkOS Node SDK User-Agent string to gather analytics about JavaScript runtime environments and versions being used by customers.

Changes

Core Implementation

  • New utility: src/common/utils/runtime-info.ts - Detects runtime type and version across Node.js, Deno, Bun, Cloudflare Workers, and other environments
  • User-Agent enhancement: Modified createUserAgent() method in src/workos.ts to include runtime information in standard format
  • Error handling: Graceful fallbacks when runtime version detection fails

User-Agent Format

Before: workos-node/8.0.0-beta.1 MyApp: 1.0.0
After: workos-node/8.0.0-beta.1 (node/v20.5.0) MyApp: 1.0.0

The new format follows standard User-Agent conventions with runtime information in parentheses, maintaining backward compatibility with existing analytics parsing.

Examples

  • Node.js: workos-node/8.0.0-beta.1 (node/v20.5.0)
  • Node.js with appInfo: workos-node/8.0.0-beta.1 (node/v20.5.0) MyApp: 1.0.0
  • Deno: workos-node/8.0.0-beta.1 (deno/1.36.4)
  • Edge runtime: workos-node/8.0.0-beta.1 (edge-light)

Testing

Unit Tests

  • 17 comprehensive test cases for getRuntimeInfo() utility covering all runtime scenarios
  • Mock testing for different environments (Node.js, Deno, Bun, edge runtimes)
  • Error handling verification with graceful degradation
  • Real-world testing with actual Node.js environment

Integration Tests

  • Updated workos.spec.ts with runtime info mocking
  • Jest snapshots updated to reflect new User-Agent format
  • Backward compatibility verified for existing appInfo functionality

Benefits

For WorkOS Analytics

  • Node.js adoption tracking: Monitor which Node.js versions are most popular
  • Runtime diversity insights: Understand usage across Node.js, Deno, Bun, and edge environments
  • Support optimization: Prioritize support for popular runtime versions
  • Migration patterns: Track adoption of new JavaScript runtime versions

For Customer Support

  • Environment debugging: Quickly identify runtime-specific issues from API logs
  • Performance optimization: Focus optimization efforts on popular runtime combinations
  • Compatibility planning: Make informed decisions about runtime support

Technical Details

Runtime Detection

  • Cached detection: Uses existing detectRuntime() from env.ts for performance
  • Version extraction: Safely extracts version numbers from runtime-specific globals
  • Fallback mechanisms: Multiple strategies for version detection (e.g., Bun version from user-agent)
  • Error resilience: Never crashes, gracefully degrades to runtime name only

Implementation Approach

  • No configuration needed: Runtime info is always included (internal analytics feature)
  • Zero breaking changes: Existing functionality unchanged
  • Standards compliant: Follows established User-Agent format conventions
  • Minimal overhead: One-time detection per process with cached results

Risk Mitigation

  • Version detection failures: Graceful fallback to runtime name only
  • Performance impact: Minimal (cached detection, ~1ms overhead)
  • User-Agent length: Reasonable increase (~20 characters)
  • Privacy concerns: No personally identifiable information collected

kendallstrautman and others added 17 commits June 11, 2025 14:33
Drop support for Node 16, which is long past EOL. This will be merged
into the `version-8` branch.

>[!WARNING]
>
>Node 18 is where we're moving to, but that will also be EOL in April,
2025.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
>[!Note]
>
>This PR is against the `version-8` branch.

## Description

TSLint has been EOL for several years. This replaces it with
typeScript-eslint and provides a comparable configuration for minimal
changes to the code.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
## Description

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
>[!note]
>This is against the `version-8` branch, which drops support for Node
16, allowing for this update to happen.

## Description

Update to latest version of iron-session.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
>[!note]
>This change is against the `version-8` branch.

## Description

Upgrade to Prettier v3 and commit minimal changes resulting from that.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
>[!note]
>This change is against the `version-8` branch.

## Description

Update to latest of the following dev dependencies
- TypeScript
- ts-jest
- Jest
- Supertest

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
Adds tests and updates typing for pagination utils.
@nicknisi nicknisi requested a review from a team as a code owner June 12, 2025 15:48
@nicknisi nicknisi requested review from kendallstrautman and removed request for a team June 12, 2025 15:48
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Enhanced User-Agent string analytics by adding runtime environment detection for improved debugging and analytics tracking across different JavaScript runtimes.

  • Implemented new runtime detection utility in src/common/utils/runtime-info.ts with comprehensive environment support (Node.js, Deno, Bun, Edge)
  • Modified createUserAgent() in src/workos.ts to include runtime info like workos-node/8.0.0-beta.1 (node/v20.5.0)
  • Added thorough test coverage in src/common/utils/runtime-info.spec.ts with 17 test cases
  • Implemented graceful fallbacks for version detection failures to ensure robustness
  • Used cached detection mechanism from existing env.ts for minimal performance impact

4 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

@nicknisi nicknisi force-pushed the nicknisi/runtime-info branch from bd54a1a to eacd64d Compare June 12, 2025 16:05
@nicknisi nicknisi changed the title Add runtime analytics to User-Agent string [v8] Add runtime analytics to User-Agent string Jun 12, 2025
@nicknisi nicknisi requested a review from cmatheson June 12, 2025 20:40
@nicknisi nicknisi force-pushed the nicknisi/runtime-info branch from 4dbb78c to 96089b3 Compare June 12, 2025 20:43
@nicknisi nicknisi force-pushed the version-8 branch 2 times, most recently from 7912f61 to bee7e85 Compare June 30, 2025 19:28
@nicknisi nicknisi force-pushed the version-8 branch 2 times, most recently from 7a0eeb3 to 57b9aab Compare August 7, 2025 16:56
@nicknisi nicknisi force-pushed the version-8 branch 2 times, most recently from d4f3297 to d477188 Compare August 25, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants