Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Context hierarchy

See original GitHub issue

Context To start with, some context for this feature request. I would like to:

  1. Incrementally add contextual information to my logging, as my code progresses.
  2. Remove contextual information when I leave the context for which that data is relevant.
  3. Have console.log statements include the context

Provided solution The library doesn’t make it impossible to do this, but it lacks a bit of convenience:

  1. is currently possible by adding data either to the global logger or a local logger.
  2. is currently possible only by overwriting the entire context. This method is inconvenient for removing just the bits that are no longer relevant, and is further constrained because I cannot query the current context. As such, the only real way to do this currently is set up our own context tracking mechanism next to the one datadog provides.
  3. although we can fork local loggers from global loggers for a single extra layer of context, the console.logs made from this context wouldn’t include that additional context.

Proposed solution Include the following API and implementation:

  1. pushContext([key1: value1, ..., keyN: valueN}]) to push a bit of context into a global context array
  2. popContext() to remove one layer of context from the global context stack.

For each log statement issued, assemble a context by merging context layers, overwriting older context values with newer ones on key conflicts.

For now I am doing the above myself with some React components in my app, but I think this would be a great addition for anybody using this logging package.

Thanks in advance for your consideration!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

bcaudancommented, Oct 30, 2020

The ability to remove global context key has been added to log in v1.15.0 and to rum in v1.20.0.

PinPinIrecommented, Aug 6, 2020

We would probably need to put more though on the API but we could have something like:

// single key
logger.addContext("foo", "bar")

// multiple keys
logger.addContext({app:my-chat-app, version: 1.0})
logger.removeContext({app:my-chat-app, version: 1.0})

It will probably not be in our top priorities, but feel free to open a PR for it if you want.

This would be useful for projects that have used services like TrackJS in the past. TrackJS allows you to add metadata that can be removed when not needed anymore ( This can be helpful when debugging errors that can be hard to reproduce or to have more context when a known error is triggered. eg.

function errorHandler(statusBitmap, resourceId) {
    trackJs.addMetadata('statusBitmap', statusBitmap);
    trackJs.addMetadata('resourceId', resourceId);
    console.error('Failed to launch resource');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Organizing your feature ideas - Productboard Support
Learn best practices around setting up your feature hierarchy in our on-demand webinar. A member of team Productboard will explain key ...
Read more >
Feature request: Sub-table/hierarchical view - Suggestion Box
So I can use column relationships (parent/child) to manage an existing table of data as an indented (and collapsable) hierarchy. I've seen some ......
Read more >
Request Features in ASP.NET Core | Microsoft Learn
IHttpRequestFeature: Defines the structure of an HTTP request, including the protocol, path, query string, headers, and body. This feature is ...
Read more >
Hybrid hierarchical perspective (feature request) - OmniFocus
Currently there are two main perspective types in Omnifocus. One that shows the Project Hierarchy an done that does not.
Read more >
Show hierarchy for filtered cards | Voters - Favro - Canny
Filtering of any type in backlogs hides hierarchies, removing important context. There should be a Show Hierarchy switch on the filter menu that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found