logologo
スタート
マニュアル
開発
プラグイン
API
ホーム
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
スタート
マニュアル
開発
プラグイン
API
ホーム
logologo

クイックスタート

プラグイン開発概要
最初のプラグインを作成
プロジェクトディレクトリ構造

サーバーサイド開発

概要
プラグイン
コレクション
データベース操作
データソース管理
リソース管理
ACL権限制御
ミドルウェア
キャッシュ
イベント
リクエストコンテキスト
マイグレーション
ロガー
I18n 国際化
コマンド
定時タスク管理
テスト

クライアントサイド開発

概要
プラグイン
コンテキスト
ルーター
ACL権限制御
データソース管理
リソース
リクエスト
スタイルとテーマ
ロガー
I18n 国際化
テスト

その他

プラグインアップグレードガイド
言語一覧
依存関係の管理
ビルド
Next Pageプラグイン開発概要
AI翻訳通知

このドキュメントはAIによって翻訳されました。正確な情報については英語版をご参照ください。

#テレメトリ

実験的

NocoBase のテレメトリ (Telemetry) モジュールは、OpenTelemetry をベースにラップされています。この記事では、テレメトリモジュールを使用してトレース (Trace) やメトリクス (Metric) データを収集し、NocoBase システムのオブザーバビリティ (Observability) を向上させる方法について説明します。

#インストルメンテーション

#メトリクス

const meter = app.telemetry.metric.getMeter();
const counter = meter.createCounter('event_counter', {});
counter.add(1);

参考:

  • https://opentelemetry.io/docs/instrumentation/js/manual/#acquiring-a-meter

#トレース

const tracer = app.telemetry.trace.getTracer();
tracer.startActiveSpan();
tracer.startSpan();

参考:

  • https://opentelemetry.io/docs/instrumentation/js/manual/#acquiring-a-tracer

#ライブラリ

import { Plugin } from '@nocobase/server';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';

class InstrumentationPlugin extends Plugin {
  afterAdd() {
    this.app.on('beforeLoad', (app) => {
      app.telemetry.addInstrumentation(getNodeAutoInstrumentations());
    });
  }
}
注意

NocoBase におけるテレメトリモジュールの初期化位置は app.beforeLoad です。そのため、すべてのインストルメンテーションライブラリが NocoBase に適しているわけではありません。
例えば、instrumentation-koa は Koa のインスタンス化の前にインポートする必要があります。NocoBase の Application は Koa をベースにしていますが、テレメトリモジュールは Application のインスタンス化の後に初期化されるため、適用することができません。

参考:

  • https://opentelemetry.io/docs/instrumentation/js/libraries/

#収集

#メトリクス

import { Plugin } from '@nocobase/server';
import {
  PeriodicExportingMetricReader,
  ConsoleMetricExporter,
} from '@opentelemetry/sdk-metrics';

class MetricReaderPlugin extends Plugin {
  afterAdd() {
    this.app.on('beforeLoad', (app) => {
      app.telemetry.metric.registerReader(
        'console',
        () =>
          new PeriodicExportingMetricReader({
            exporter: new ConsoleMetricExporter(),
          }),
      );
    });
  }
}

#トレース

import { Plugin } from '@nocobase/server';
import {
  BatchSpanProcessor,
  ConsoleSpanExporter,
} from '@opentelemetry/sdk-trace-base';

class TraceSpanProcessorPlugin extends Plugin {
  afterAdd() {
    this.app.on('beforeLoad', (app) => {
      app.telemetry.trace.registerProcessor(
        'console',
        () => new BatchSpanProcessor(new ConsoleSpanExporter()),
      );
    });
  }
}

参考:

  • https://opentelemetry.io/docs/instrumentation/js/exporters