@infrastack/otel
v0.2.1
Published
Official Infrastack OpenTelemetry SDK for JavaScript.
Downloads
57
Readme
Infrastack Otel
Official Infrastack OpenTelemetry SDK for JavaScript.
Visit the Documentation for more information.
infrastack.ai - Next-Gen Application Intelligence for Developers.
GitHub
@infrastack/otel
is a simple and easy-to-use open-source package which helps setting up OpenTelemetry tracing
⚡ Utilize this package to instrument your applications and get started with OpenTelemetry blazingly fast!
📦 Installation
$ npm install @infrastack/otel
Usage
To configure Infrastack SDK, call the init
function in the instrumentation.ts
:
import { Infrastack } from "@infrastack/otel";
Infrastack.init();
This will capture all the configurations from the .env
file. This produces an output similar to below:
Exporter endpoint is set as: https://collector.infrastack.ai
Found an API Key: sk-1*****f5af
Service name is set as: fly-bright-dog
Service version is set as: 0.0.1
Application is now instrumented with infrastack.ai
Environment variables (.env)
INFRASTACK_LOGS_ENABLED=true/false # Enables or disables SDK startup logs
INFRASTACK_TAGS='[{"key": "key1", "value": "value1"}, {"key": "key2", "value": "value2"}]' # These tags are directly injected into ResourceAttributes of each span.
INFRASTACK_ENVIRONMENT=DEBUG/DEV/PROD
INFRASTACK_API_KEY=YOUR_INFRASTACK_API_KEY
OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_EXPORTER_ENDPOINT
OTEL_EXPORTER_OTLP_HEADERS=YOUR_OTEL_EXPORTER_HEADERS # For infrastack.ai : "infrastack-api-key=sk-**********************"
OTEL_SERVICE_NAME=YOUR_SERVICE_NAME
OTEL_SERVICE_VERSION=YOUR_SERVICE_VERSION
OTEL_SERVICE_INSTANCE_ID=YOUR_SERVICE_INSTANCE_ID
OTEL_K8S_NAMESPACE=YOUR_K8S_POD_NAMESPACE
OTEL_K8S_POD_NAME=YOUR_K8S_POD_NAME
Initializing the SDK with configuration
You can initialize the SDK with configuration, which overrides the environment variables.
- First, gather the related imports from
@infrastack/otel
in yourinstrumentation.ts
import { Infrastack, Instrumentation, Configuration, Environment, Tag } from "@infrastack/otel";
- Then, set up your SDK options.
const myTags : Tag[] = [
{key: "aws-region", value: "us-west-2"},
{key: "aws-account-id", value: "123456789012"}
]
const configuration : Configuration = {
serviceName: "my-cool-service",
serviceVersion: "1.0.0",
environment: Environment.DEV,
tags: myTags,
logsEnabled: false,
podNamespace: "my-cluster",
podName: "my-pod"
}
- Initialize the Infrastack SDK
Infrastack.init(configuration);
Partial configuration is also possible. For example:
const configuration : Configuration = {
logsEnabled:false
}
Infrastack.init(configuration);
This disables Infrastack SDK logs but collects the rest of the configuration from your .env
file if available.
Custom spans
To produce manual spans in your code, you can seamlessly use the OpenTelemetry API:
import { trace } from "@opentelemetry/api";
const span = trace.getTracer("user-service").startSpan("fetch-user-data");
Troubleshooting
If you are having issues, feel free to contact us!
Contributing
@infrastack/otel
is an open-source project and contributions are always welcomed! Here are some guidelines to the so:
- Clone the repository
$ git clone https://github.com/infrastackai/infrastack.git
- cd into the this package's directory
$ cd packages/javascript/otel
- Check out your feature branch
$ git checkout -b your-feature-branch
- Install the dependencies
$ npm i
- Implement your feature logic.
- Since we are using the tool called
changeset
to publish releases. Create a changeset and fill the prompted.
$ npx changeset
- Create a pull request in the repository from this URL and invite someone active from the repository.
We appreciate your help 😊