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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ apiKey: 'sk-1*****f5af', serviceName: 'my-service'})
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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ serviceName: 'my-service'})
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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ serviceVersion: '1.0.0', serviceName: 'my-service'})
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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ developmentMode: true, serviceName: 'my-service'})
Development mode is only recommended for development purposes. It is not recommended for production.
By default, when you set up the SDK and run your application, you will see logs in the console as below:
Copy
Exporter endpoint is set as: https://collector.infrastack.aiFound an API Key: sk-1*****f5afService name is set as: infrastack-exampleService version is set as: 0.0.1Application 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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ logsEnabled: false, serviceName: 'my-service'})
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.
Copy
import { Infrastack, Tag } from '@infrastack/otel'const tags: Tag[] = [{ key: 'environment', value: 'production' }]Infrastack.init({ tags: tags, serviceName: 'my-service'})
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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ endpoint: 'http://localhost:4317', serviceName: 'my-service'})
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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ protocol: Protocol.HTTP, serviceName: 'my-service'})
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.
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.
Copy
import { Infrastack } from '@infrastack/otel'Infrastack.init({ disabledInstrumentations: [Instrumentation.HTTP], serviceName: 'my-service'})