JSPM

@opentelemetry/instrumentation-fetch

0.200.0-dev.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 693688
  • Score
    100M100P100Q205400F
  • License Apache-2.0

OpenTelemetry instrumentation for fetch http client in web browsers

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@opentelemetry/instrumentation-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    OpenTelemetry Fetch Instrumentation for web

    NPM Published Version Apache License

    Note: This is an experimental package under active development. New releases may include breaking changes.

    This module provides auto instrumentation for web using fetch. (Note: This instrumentation does not instrument Node.js' fetch. See @opentelemetry/instrumentation-undici for that.)

    Installation

    npm install --save @opentelemetry/instrumentation-fetch

    Usage

    import {
      ConsoleSpanExporter,
      SimpleSpanProcessor,
      WebTracerProvider,
    } from '@opentelemetry/sdk-trace-web';
    import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
    import { ZoneContextManager } from '@opentelemetry/context-zone';
    import { registerInstrumentations } from '@opentelemetry/instrumentation';
    
    const provider = new WebTracerProvider({
      spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
    });
    
    provider.register({
      contextManager: new ZoneContextManager(),
    });
    
    registerInstrumentations({
      instrumentations: [new FetchInstrumentation()],
    });
    
    // or plugin can be also initialised separately and then set the tracer provider or meter provider
    const fetchInstrumentation = new FetchInstrumentation();
    const provider = new WebTracerProvider({
      spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
    });
    provider.register({
      contextManager: new ZoneContextManager(),
    });
    fetchInstrumentation.setTracerProvider(provider);
    
    // and some test
    
    fetch('http://localhost:8090/fetch.js');
    

    Example Screenshots

    Screenshot of the running example Screenshot of the running example Screenshot of the running example

    See examples/tracer-web/fetch for a short example.

    Fetch Instrumentation options

    Fetch instrumentation plugin has few options available to choose from. You can set the following:

    Options Type Description
    applyCustomAttributesOnSpan FetchCustomAttributeFunction Function for adding custom attributes
    requestHook FetchRequestHookFunction Function for adding custom attributes or headers before the request is handled
    ignoreNetworkEvents boolean Disable network events being added as span events (network events are added by default)
    measureRequestSize boolean Measure outgoing request length (outgoing request length is not measured by default)

    Semantic Conventions

    This package uses @opentelemetry/semantic-conventions version 1.22+, which implements Semantic Convention Version 1.7.0

    Attributes collected:

    Attribute Short Description
    http.status_code HTTP response status code
    http.host The value of the HTTP host header
    http.user_agent Value of the HTTP User-Agent header sent by the client
    http.scheme The URI scheme identifying the used protocol
    http.url Full HTTP request URL
    http.method HTTP request method
    http.request_content_length_uncompressed Uncompressed size of the request body, if any body exists

    License

    Apache 2.0 - See LICENSE for more information.