simple-opentelemetry
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

simple-opentelemetry

Otelic.com - easiest way to add Logs, Traces & Alerts to NodeJS app

The easiest way to add OpenTelemetry Logs & Traces to NodeJS app.

Powered by Otelic.com magic ✨🧙‍♂️

Get free API Key at https://app.otelic.com/ at Workspace Settings

Step 1: Define env variables

These 3 env variables config Otelic Simple OpenTelemetry package:

Only required is OTELIC_API_KEY

OTELIC_API_KEY = "YOUR_FREE_API_KEY";
OTELIC_APP_NAME = "My app";
OTELIC_SERVICE_NAME = "My service";

e.g. in your package.json

{
  "scripts": {
    "run": "export OTELIC_API_KEY=\"YOUR_FREE_API_KEY\" && export OTELIC_APP_NAME=\"My App\" && export OTELIC_SERVICE_NAME=\"My service\" && node index.js"
  }
}

You have to load these env variables before importing

Step 2: Import the package

Make sure it happens before anything else, while it will auto-instrument your console, SQL, Mongo, 3rd-party services code to create traces, spans.

import "simple-opentelemetry";

That's it :)

Make sure to have this as first thing in your app.

Once done, go to https://app.otelic.com/ and enjoy your free searchable Logs, Traces & Alerts.

Check out related guides

Enjoy 🎉






I get error "OTELIC_API_KEY" is not defined and I defined it like this 😭😭😭

process.env.OTELIC_API_KEY = "MY_FREE_API_KEY";
import "simple-opentelemetry";

Your imported file is executed immediately before env variables were actually available. Check how to define env variables below:

Option 1: Define env variables inside package.json

Looks a bit messy, but it's super easy, works every time and is scoped to this process only.

You can have multiple scripts defined for local, production, staging env.

{
  "scripts": {
    "run": "export OTELIC_API_KEY=\"YOUR_FREE_API_KEY\" && export OTELIC_APP_NAME=\"My App\" && export OTELIC_SERVICE_NAME=\"My service\" && node index.js"
  }
}

Option 2: Create index file which would define env before importing your actual app's index. file

process.env.OTELIC_API_KEY = "YOUR_FREE_API_KEY";
process.env.OTELIC_APP_NAME = "My app";
process.env.OTELIC_SERVICE_NAME = "My service";

import "app/index.ts";

Inside app/index.ts Your first line would be

import "simple-opentelemetry";

Option 3: define for all server at once

In your server look for file /etc/environment in new line you can add.

OTELIC_API_KEY="YOUR_FREE_API_KEY";
OTELIC_APP_NAME="My app";
OTELIC_SERVICE_NAME="My service";

Keep in mind this will be set for all processes in the machine.

Option 4: define inside pm2 config

pm2 process can be run with ecosystem.config.js like this:

pm2 start ecosystem.config.js

This file has many more options related to RAM usage, restart policy and else. Search for pm2 ecosystem file official docs to learn more.

ecosystem.config.js sample file:

module.exports = {
  apps: [
    {
      name: "My app",
      script: "./app.js", // Path to your application's entry file
      env: {
        OTELIC_API_KEY: "YOUR_FREE_API_KEY",
        OTELIC_APP_NAME: "My app",
        OTELIC_SERVICE_NAME: "My service",
      },
    },
  ],
};

Package Sidebar

Install

npm i simple-opentelemetry

Weekly Downloads

16

Version

1.0.12

License

MIT

Unpacked Size

25.3 kB

Total Files

11

Last publish

Collaborators

  • liesislukas