This package has been deprecated

Author message:

Package renamed to @opentelemetry/context-zone-peer-dep, see https://github.com/open-telemetry/opentelemetry-js

@opentelemetry/scope-zone-peer-dep
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

OpenTelemetry Scope Zone Peer Dependency

Gitter chat NPM Published Version dependencies devDependencies Apache License

This module provides Zone Scope Manager with a peer dependency for zone-js for Web applications. If you use Angular you already have the zone-js and you should use this package. If you don't have your own zone-js please use @opentelemetry/scope-zone

Installation

npm install --save @opentelemetry/scope-zone-peer-dep

Usage

import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { ZoneScopeManager } from '@opentelemetry/scope-zone-peer-dep';

const webTracerWithZone = new WebTracer({
  scopeManager: new ZoneScopeManager()
});
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

// Example how the ZoneScopeManager keeps the reference to the correct scope during async operations
const span1 = webTracerWithZone.startSpan('foo1');
webTracerWithZone.withSpan(span1, () => {
  console.log('Current span is span1', webTracerWithZone.getCurrentSpan() === span1);
  setTimeout(() => {
    const span2 = webTracerWithZone.startSpan('foo2');
    console.log('Current span is span1', webTracerWithZone.getCurrentSpan() === span1);
    webTracerWithZone.withSpan(span2, () => {
      console.log('Current span is span2', webTracerWithZone.getCurrentSpan() === span2);
      setTimeout(() => {
        console.log('Current span is span2', webTracerWithZone.getCurrentSpan() === span2);
      }, 500);
    });
    // there is a timeout which still keeps span2 active
    console.log('Current span is span2', webTracerWithZone.getCurrentSpan() === span2);
  }, 500);
  console.log('Current span is span1', webTracerWithZone.getCurrentSpan() === span1);
});

Useful links

License

Apache 2.0 - See LICENSE for more information.

Dependents (1)

Package Sidebar

Install

npm i @opentelemetry/scope-zone-peer-dep

Weekly Downloads

1

Version

0.4.0

License

Apache-2.0

Unpacked Size

35.5 kB

Total Files

13

Last publish

Collaborators

  • pichlermarc
  • bogdandrutu
  • dyladan