Skip to main content
Home

grammY plugin to allow instrumentation with open telemetry

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.0.2)

grammY OpenTelemetry

Integrates OpenTelemetry into grammY.

Development is in progress.

Description

After a lot of thought and research, we came to the conclusion that it would be bad to integrate with a particular technology, especially if it is possible to support many at once. Fortunately, there is the OpenTelemetry project, which defines a single approach to collecting and managing telemetry that integrates perfectly with many existing services. However, there are some problems with it:

  1. The JS toolkit is quite young, so many things are experimental or just under development, which makes it difficult to use.
  2. They split the Web and Node.js tools into separate packages, which will cause support issues in the future.
  3. They are very fond of autoinstrumentation, which intercepts require/import calls and patches the requested package, which we think is a very, very bad pattern that we don't want to impose on grammY users.

This plugin allows you to use open telemetry without those caveats.

Usage

import { Bot, Context } from "npm:grammy";
import { getHttpTracer, openTelemetryTransformer } from "jsr:@roz/grammy-opentelemetry";

const bot = new Bot<Context>("token");

bot.api.config.use(openTelemetryTransformer(getHttpTracer("my-bot")));

bot.command("start", (ctx) => {
  // Creates a new span for the current command,
  // tied to the span of the current update.
  return ctx.openTelemetry.trace(
    // span name
    "command.start",
    // span attributes
    { ["user.id"]: ctx.from?.id },
    // span actions
    async (span) => {
      span.addEvent("command.start.handle");
      await ctx.reply("Hello! I'm a bot!");
      await ctx.reply("I can help you with a lot of things!");
    },
  );
});

bot.start();

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@roz/grammy-opentelemetry

Import symbol

import * as grammy_opentelemetry from "@roz/grammy-opentelemetry";
or

Import directly with a jsr specifier

import * as grammy_opentelemetry from "jsr:@roz/grammy-opentelemetry";

Add Package

pnpm i jsr:@roz/grammy-opentelemetry
or (using pnpm 10.8 or older)
pnpm dlx jsr add @roz/grammy-opentelemetry

Import symbol

import * as grammy_opentelemetry from "@roz/grammy-opentelemetry";

Add Package

yarn add jsr:@roz/grammy-opentelemetry
or (using Yarn 4.8 or older)
yarn dlx jsr add @roz/grammy-opentelemetry

Import symbol

import * as grammy_opentelemetry from "@roz/grammy-opentelemetry";

Add Package

npx jsr add @roz/grammy-opentelemetry

Import symbol

import * as grammy_opentelemetry from "@roz/grammy-opentelemetry";

Add Package

bunx jsr add @roz/grammy-opentelemetry

Import symbol

import * as grammy_opentelemetry from "@roz/grammy-opentelemetry";