Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/context-async-hooks

Package Overview
Dependencies
Maintainers
3
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/context-async-hooks

OpenTelemetry AsyncHooks-based Context Manager

  • 1.24.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @opentelemetry/context-async-hooks?

The @opentelemetry/context-async-hooks package is part of the OpenTelemetry project, which provides a set of APIs, libraries, agents, and instrumentation to create and manage telemetry data (metrics, logs, and traces) for cloud-native software. Specifically, this package leverages Node.js' async_hooks module to implement context propagation for asynchronous operations. This is crucial for tracing and logging in asynchronous applications, as it allows developers to maintain context across asynchronous boundaries.

What are @opentelemetry/context-async-hooks's main functionalities?

Context Management

This feature allows for the management of context across asynchronous operations. It uses the AsyncLocalStorage class to create a new context storage, run a function within this context, and retrieve values from this context later in the async flow.

const { AsyncLocalStorage } = require('@opentelemetry/context-async-hooks');
const asyncLocalStorage = new AsyncLocalStorage();

asyncLocalStorage.run(new Map(), () => {
  asyncLocalStorage.getStore().set('key', 'value');
  someAsyncOperation().then(() => {
    console.log(asyncLocalStorage.getStore().get('key')); // Outputs: 'value'
  });
});

Context Propagation

This feature demonstrates how to set up the AsyncLocalStorageContextManager to work with OpenTelemetry's API for global context propagation. This setup is essential for tracing asynchronous operations across different parts of an application.

const { propagation } = require('@opentelemetry/api');
const { AsyncLocalStorageContextManager } = require('@opentelemetry/context-async-hooks');

const contextManager = new AsyncLocalStorageContextManager();
propagation.setGlobalPropagator(contextManager);

// Now, the context is propagated across asynchronous calls automatically.

Other packages similar to @opentelemetry/context-async-hooks

Keywords

FAQs

Package last updated on 24 Apr 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc