Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@opentelemetry/context-base
Advanced tools
@opentelemetry/context-base is a package that provides a base implementation for context management in OpenTelemetry. It allows for the creation, management, and propagation of context across different parts of an application, which is essential for distributed tracing and telemetry data collection.
Creating a Context
This feature allows you to create a new context instance. Contexts are used to store and propagate data across different parts of an application.
const { BaseContext } = require('@opentelemetry/context-base');
const context = new BaseContext();
console.log(context);
Setting and Getting Values in Context
This feature allows you to set and get values in a context. This is useful for storing data that needs to be accessed across different parts of an application.
const { BaseContext } = require('@opentelemetry/context-base');
const context = new BaseContext();
const key = 'exampleKey';
const value = 'exampleValue';
const updatedContext = context.setValue(key, value);
console.log(updatedContext.getValue(key)); // Outputs: 'exampleValue'
Context Propagation
This feature demonstrates how context can be propagated across different functions or parts of an application. This is essential for maintaining state and data consistency in distributed systems.
const { BaseContext } = require('@opentelemetry/context-base');
const context = new BaseContext();
const key = 'exampleKey';
const value = 'exampleValue';
const updatedContext = context.setValue(key, value);
function someFunction(ctx) {
console.log(ctx.getValue(key)); // Outputs: 'exampleValue'
}
someFunction(updatedContext);
The 'async_hooks' module in Node.js provides an API to track asynchronous resources. It allows you to create and manage execution contexts, similar to @opentelemetry/context-base. However, 'async_hooks' is more low-level and is part of the Node.js core, whereas @opentelemetry/context-base is specifically designed for telemetry and tracing.
The 'cls-hooked' package provides a way to manage context across asynchronous calls using continuation-local storage. It is similar to @opentelemetry/context-base in that it allows for context propagation, but it uses a different mechanism and is not specifically designed for telemetry.
The 'zone.js' library provides a way to manage execution contexts in JavaScript applications. It is similar to @opentelemetry/context-base in that it allows for context management and propagation, but it is more commonly used in Angular applications for managing asynchronous operations.
This package provides the ContextManager interface (which is used by concrete implementations) and a no-op implementation (which is used internally when no context propagation is defined). It's intended for use both on the server and in the browser.
To understand why they exists, we'll need to understand how Javascript works: when you make native function call (networks, setInterval etc) you generally call C++ code that will later callback your own code.
A common issue when tracing a request in javascript is to link the function that have made the native call to the callback that the native code called when the response is there. Imagine you want to track for which user you made the request, you need some sort of "context/context aware storage".
ContextManager's aim to offer exactly that, it's API offer to store an object in the current context (with()
) and if needed, bind()
to a specific function call to find it back when the callback fire, which can later get retrieved using active()
.
This package only include the interface and a Noop implementation, for more information please see the async-hooks based ContextManager for NodeJS.
Apache 2.0 - See LICENSE for more information.
FAQs
OpenTelemetry Base Context Manager
The npm package @opentelemetry/context-base receives a total of 95,611 weekly downloads. As such, @opentelemetry/context-base popularity was classified as popular.
We found that @opentelemetry/context-base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.