What you will learn

  • Configuring the infrastack.ai Javascript SDK for your needs

Prerequisites

  • An application using the infrastack.ai Javascript SDK @infrastack/otel

Overview

Our Javascript SDK provides flexibility to developers to configure the SDK. There are 2 ways to configure the SDK:

  • Via environment variables
  • Via code
What you provide in the code will override what you provide in the environment variables

Setting the API Key

API key is required when you initialize the SDK to use it with infrastack.ai.

To set the API key, you can set the apiKey option in the Infrastack.init function or set the INFRASTACK_API_KEY environment variable.


Setting the service name

The service name is used to identify the service in the infrastack.ai dashboard.

To set the service name, you can set the serviceName option in the Infrastack.init function or set the OTEL_SERVICE_NAME environment variable. If you do not provide a service name from either of the options, it will generate a random service name.


Setting the service version

The service version is used to identify the version of the service in the infrastack.ai dashboard. It becomes useful to capture deployment information and other versioning information.

If you do not provide a service version from either of the options, it will default to 0.0.1.

To set the service version, you can set the serviceVersion option in the Infrastack.init function or set the OTEL_SERVICE_VERSION environment variable.


Development mode

Development mode is disabled by default. In that case, it will not log anything to the console and will use BatchSpanProcessor for span exports.

Visit the Documentation OpenTelemetry - Picking the right span processor for more information.

To toggle development mode, you can set the developmentMode option to true in the Infrastack.init function or set the INFRASTACK_DEVELOPMENT_MODE environment variable to true.

Development mode is only recommended for development purposes. It is not recommended for production.

Disabling the SDK logs

By default, when you set up the SDK and run your application, you will see logs in the console as below:

Exporter endpoint is set as: https://collector.infrastack.ai
Found an API Key: sk-1*****f5af
Service name is set as: infrastack-example
Service version is set as: 0.0.1
Application is now instrumented with infrastack.ai

To disable them for cleaner startup logs for your application, you can set the logsEnabled option to false in the Infrastack.init function or set the INFRASTACK_LOGS_ENABLED environment variable to false.


Tags

You can define a set of tags to enrich your spans. It is also recommended to add the tag for your environment (Production, Staging, Development etc.)

All of these tags will be added to every span that is created.

To set the tags, you can set the tags option in the Infrastack.init function or set the INFRASTACK_TAGS environment variable.


Configuring the exporter endpoint

By default, the SDK will use the infrastack.ai collector endpoint. However, it can be overriden to use a different endpoint.

To set the endpoint, you can set the endpoint option in the Infrastack.init function or set the OTEL_EXPORTER_OTLP_ENDPOINT environment variable.


Configuring the exporter protocol

By default, the SDK will use the grpc protocol. However, it can be overriden to use a different protocol.

To set the protocol, you can set the protocol option in the Infrastack.init function or set the OTEL_EXPORTER_OTLP_PROTOCOL environment variable.

By doing so, the SDK will use the http protocol to export the spans to the collector.

If you are using your own collector, you will need to set the correct endpoint and protocol.

Disabling instrumentations

You can disable specific instrumentations by setting the disabledInstrumentations option in the Infrastack.init function or set the INFRASTACK_DISABLED_INSTRUMENTATIONS environment variable. List of instrumentations can be found here.