Skip to content

feat: Instrumentation#2527

Open
tusharpandey13 wants to merge 4 commits intomainfrom
feat/instrumentation
Open

feat: Instrumentation#2527
tusharpandey13 wants to merge 4 commits intomainfrom
feat/instrumentation

Conversation

@tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Feb 18, 2026

This change adds configurable instrumentation support to the SDK, enabling emitting events at various critical points of the SDK flows.
These events can be consumed using a callback.

Some use-cases for this feature:

  • Event logging
  • Debugging
  • Event streaming and reactive workflows

Changes

Instrumentation infra:
These changes enable the actual instrumentation support.

  • instrumentation-emitter.ts: InstrumentationEmitter class, helper methods
  • instrumentation.flow.test.ts‎ & instrumentation.test.ts‎ : Tests
  • types/instrumentation.ts: Type definitions
  • EXAMPLES.md: Documentation

Event call sites:
These changes add call sites to existing SDK code at important points. PII data is not sent to emitter from codebase itself, removing the need for a filteration step.

  • auth-client.ts: Most of the SDK flows
  • client.ts: Configuration, one call site

Usage

1. Option1: Environment Variables

AUTH0_LOGGING_TARGET=console
AUTH0_LOGGING_LEVEL=info

Option 2: Custom callback

Configure a callback in Auth0ClientOptions:

export const auth0 = new Auth0Client({
  instrumentation: {
    logger: (event) => {
      // do what you want with the event here
      console.log(`[${event.level}] ${event.event}`, event.data);
    },
  },
});

Tests

Added unit and flow tests for complete integration.

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner February 18, 2026 15:15
@tusharpandey13 tusharpandey13 marked this pull request as draft February 18, 2026 15:15
return new Promise((resolve) =>
setTimeout(() => {
resolve(undefined);
resolveLogger!();

Check failure

Code scanning / CodeQL

Invocation of non-function Error

Callee is not a function: it has type undefined.

Copilot Autofix

AI about 18 hours ago

In general, to fix an “invocation of non-function” issue, ensure that any value you call as a function is guaranteed to be a function at runtime, either by initializing it appropriately, guarding the call with a type check, or removing the call if it is unnecessary.

Here, resolveLogger is intended to be a function used to signal when the logger’s internal work has finished, but in this test we never assign it or await it. The test only cares that the auth flow does not wait for the slow logger; it never inspects or uses resolveLogger. Therefore the simplest, behavior-preserving fix is to stop calling resolveLogger entirely. The promise returned by slowLogger already resolves via resolve(undefined);, which is sufficient for the test’s purpose. Removing the resolveLogger!(); call ensures we no longer attempt to invoke a possibly-undefined value, while keeping the rest of the behavior (a slow, non-awaited logger) intact.

Concretely, in src/server/instrumentation.flow.test.ts, within the "EC-10: Slow async logger" describe block, update the setTimeout body so that it only calls resolve(undefined); and does not reference resolveLogger. You may optionally also remove the unused resolveLogger variable declaration, but given the instruction to minimize changes, we can leave the declaration in place even though it is unused; the key is to remove the unsafe invocation.

Suggested changeset 1
src/server/instrumentation.flow.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/server/instrumentation.flow.test.ts b/src/server/instrumentation.flow.test.ts
--- a/src/server/instrumentation.flow.test.ts
+++ b/src/server/instrumentation.flow.test.ts
@@ -603,7 +603,6 @@
         return new Promise((resolve) =>
           setTimeout(() => {
             resolve(undefined);
-            resolveLogger!();
           }, 5000)
         ) as any;
       };
EOF
@@ -603,7 +603,6 @@
return new Promise((resolve) =>
setTimeout(() => {
resolve(undefined);
resolveLogger!();
}, 5000)
) as any;
};
Copilot is powered by AI and may make mistakes. Always verify output.
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.60%. Comparing base (bc63577) to head (85d56f4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2527      +/-   ##
==========================================
+ Coverage   90.15%   90.60%   +0.45%     
==========================================
  Files          51       53       +2     
  Lines        6439     6708     +269     
  Branches     1292     1333      +41     
==========================================
+ Hits         5805     6078     +273     
+ Misses        623      619       -4     
  Partials       11       11              

☔ View full report in Codecov by Sentry.
📢 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.

@tusharpandey13 tusharpandey13 marked this pull request as ready for review February 19, 2026 06:22
@tusharpandey13 tusharpandey13 changed the title feat: Add instrumentation support feat: Instrumentation Feb 19, 2026
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.

2 participants

Comments