Skip to content

added API level logs sampling and person level enabling feature#1329

Merged
piyushKumar-1 merged 1 commit into
mainfrom
logging-imprv
Jun 4, 2026
Merged

added API level logs sampling and person level enabling feature#1329
piyushKumar-1 merged 1 commit into
mainfrom
logging-imprv

Conversation

@piyushKumar-1
Copy link
Copy Markdown
Member

@piyushKumar-1 piyushKumar-1 commented Jun 4, 2026

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates

Description

Additional Changes

  • This PR modifies the database schema (database migration added)
  • This PR modifies dhall configs/environment variables

Motivation and Context

How did you test it?

Checklist

  • I formatted the code and addressed linter errors ./dev/format-all-files.sh
  • I reviewed submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

Summary by CodeRabbit

  • New Features
    • Introduced staggered dynamic log levels that apply logging rules to a configurable percentage of requests, reducing overhead
    • Log level configuration now supports optional sampling percentages
    • Added token-based lookup support for dynamic log level configuration with backward-compatible serialization

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR introduces staggered dynamic logging capabilities by adding a DynamicLogLevel type that pairs log levels with optional randomization percentages, and integrates optional token-based lookup fallback into the dynamic log-level resolution path. The stored configuration type is updated from LogLevel to DynamicLogLevel throughout the logging infrastructure.

Changes

Staggered Dynamic Log Levels with Token-based Lookup

Layer / File(s) Summary
DynamicLogLevel Type and JSON Serialization
lib/mobility-core/src/Kernel/Types/Logging.hs
Introduces DynamicLogLevel data type with logLevel and optional staggerPercentage fields, implementing backward-compatible FromJSON/ToJSON instances that serialize to bare LogLevel when no stagger is present and to a two-element form when stagger percentage is present.
ORM Storage Type Instance
lib/mobility-core/src/Kernel/Beam/Types.hs
Updates OptionEntity instance for DynamicLogLevelConfig to use HashMap Text KTC.DynamicLogLevel instead of HashMap Text KTC.LogLevel, aligning the stored map value type with the new type definition.
Log Level Resolution with Stagger Logic
lib/mobility-core/src/Kernel/Tools/Logging.hs
Introduces resolveDynamicLogLevel function that conditionally applies the configured log level based on a random percentage toss when stagger is present, or directly when absent. Updates withDynamicLogLevel to use the new resolution logic, getDynamicLogLevelConfig return type to HM.HashMap Text DynamicLogLevel, and DB decoding target.
Request Token Extraction and Dynamic Lookup
lib/mobility-core/src/Kernel/Utils/App.hs
Extracts optional token header from request context and passes it through modifier function signature. Updates withModifiedEnv' to use token as fallback lookup key in dynamic log-level configuration when URL-based lookup does not yield a value. Wires token argument through withModifiedEnv wrapper.

Sequence Diagram

sequenceDiagram
  participant Request as Request Handler
  participant withModifiedEnvFn as withModifiedEnvFn
  participant ModifierFn as Modifier Function
  participant getDynamicLogLevelConfig as getDynamicLogLevelConfig
  participant resolveDynamicLogLevel as resolveDynamicLogLevel

  Request->>withModifiedEnvFn: incoming request with headers
  withModifiedEnvFn->>withModifiedEnvFn: extract token from headers
  withModifiedEnvFn->>ModifierFn: pass requestId, sessionId, mbToken
  ModifierFn->>getDynamicLogLevelConfig: fetch HashMap Text DynamicLogLevel
  ModifierFn->>ModifierFn: lookup by sanitized URL
  alt URL match found
    ModifierFn->>resolveDynamicLogLevel: resolve with DynamicLogLevel
  else URL no match
    ModifierFn->>ModifierFn: lookup by token
    ModifierFn->>resolveDynamicLogLevel: resolve with DynamicLogLevel
  end
  resolveDynamicLogLevel->>resolveDynamicLogLevel: random percentage toss if stagger present
  resolveDynamicLogLevel-->>ModifierFn: Maybe LogLevel
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A token hops through request headers, logging staggered and true,
With random percentages dancing, we log just a subset or two,
From LogLevel to DynamicLogLevel, backward-compatible and neat,
The fallback lookup takes the stage, making the story complete!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main changes: adding dynamic log level configuration with staggered sampling (API-level) and per-entity enabling (person-level) features across the logging system.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch logging-imprv

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@piyushKumar-1 piyushKumar-1 merged commit 3dc55f8 into main Jun 4, 2026
1 of 2 checks passed
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.

1 participant