Opentelemetryのロゴ

Opentelemetry

コミュニティ
mizchi
opentelemetry

特定のプラットフォームに依存しないOpenTelemetryリファレンスです。シグナルの選択(traces/metrics/logs)、スパンの設計、コンテキスト伝播(W3C TraceContext)、サンプリング戦略、OTLPエクスポーターの設定を扱います。設計上の判断を適切に行うため、OTelの計装コードを書く前に使います。プラットフォーム固有のスキル(otel-node、cloudflare-workers-otel-utels)は、このスキルを基盤として追加の内容を提供します。

概要

公開者mizchi
リポジトリskills
スキル名opentelemetry
スター
333
フォーク
4
同梱ファイル
指示のみ
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    mizchiがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Opentelemetry」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/mizchi/skills/tree/main/opentelemetry
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mizchi/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/opentelemetry .claude/skills/opentelemetry
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでOpentelemetryを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にOpentelemetryを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Opentelemetryは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

OpenTelemetry — Core Patterns

Signal Selection

Pick the right signal before writing code:

SignalUse forCost
TracesRequest lifecycle, latency attribution, distributed causalityHigh (per-request)
MetricsAggregated counts, rates, histograms — dashboards and alertingLow (pre-aggregated)
LogsDiscrete events with context — errors, audit, debugMedium

Rule of thumb: metrics answer "how often / how fast", logs answer "what happened", traces answer "why". Don't use traces where metrics suffice.

Span Design

Naming convention

<verb> <noun>         →  "fetch user", "send email"
<provider>.<operation> →  "db.query", "http.get", "cache.set"

Never put variable data (IDs, values) in the span name — use attributes. A span name is a cardinality key in your trace index.

Attributes

typescript
span.setAttributes({
  "db.system": "sqlite",
  "db.operation": "select",
  "db.sql.table": "users",
  "user.id": userId,          // high-cardinality: OK as attribute, not in name
});

Follow OpenTelemetry Semantic Conventions for well-known attribute names (http.*, db.*, rpc.*, etc.) — backends and APMs key off these.

Events vs child spans

  • Event: instant point-in-time inside the current operation (span.addEvent("cache_miss"))
  • Child span: has its own duration, latency matters, useful in trace waterfall

Status and exceptions

typescript
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
span.recordException(err);  // adds exception.type / exception.message / exception.stacktrace

Call both on error. recordException alone does not flip status to ERROR — the span appears successful in the UI.

Guarantee span.end()

typescript
// ✓ callback form guarantees end()
tracer.startActiveSpan("operation", (span) => {
  try {
    return doWork();
  } catch (e) {
    span.recordException(e as Error);
    span.setStatus({ code: SpanStatusCode.ERROR });
    throw e;
  } finally {
    span.end();
  }
});

A span that is never ended leaks in the processor queue and may never export.

Context Propagation

W3C TraceContext (traceparent / tracestate) is the standard. Inject on outgoing requests, extract on incoming:

typescript
import { propagation, context } from "@opentelemetry/api";

// Outgoing HTTP
const carrier: Record<string, string> = {};
propagation.inject(context.active(), carrier);
fetch(url, { headers: carrier });

// Incoming (server handler)
const ctx = propagation.extract(context.active(), request.headers);
tracer.startActiveSpan("handle request", { context: ctx }, (span) => {
  // span is now a child of the upstream trace
});

Most common bug: creating a span without extracting the incoming context → the trace waterfall breaks into disconnected root spans. Always extract before starting the root server span.

Sampling

StrategyWhen
AlwaysOnDev / low-traffic staging
TraceIdRatioBased(0.1)High-volume production — sample 10% of new traces
ParentBased(root: TraceIdRatioBased)Recommended default — respects upstream decision, samples new roots at ratio
Tail sampling (OTel Collector)Need 100% of errors regardless of head-sample decision

ParentBased prevents the failure mode where the upstream samples a trace but the downstream drops it (broken waterfall).

OTLP Exporter Config

typescript
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";

const exporter = new OTLPTraceExporter({
  url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT + "/v1/traces",
  headers: { Authorization: `Bearer ${process.env.OTEL_API_KEY}` },
});

provider.addSpanProcessor(
  new BatchSpanProcessor(exporter, {
    maxQueueSize: 512,
    scheduledDelayMillis: 2000,
    exportTimeoutMillis: 10_000,
  })
);

Use BatchSpanProcessor in production — it is async and low-overhead. SimpleSpanProcessor blocks the event loop; use only for local debugging.

Common Pitfalls

  • provider.register() not called: SDK is configured but nothing is exported. Call before any instrumentation runs.
  • ESM + auto-instrumentation (Node.js): require-in-the-middle hooks do not fire for ESM static imports. See otel-node for the workaround.
  • Cloudflare Workers: no Node.js runtime, fetch-boundary instrumentation needed. See cloudflare-workers-otel-utels.
  • Span name includes dynamic data: explodes trace index cardinality. Move to attributes.
  • No W3C propagation on outbound calls: distributed trace breaks — downstream spans appear as orphaned roots.

よくある質問

AIスキル「Opentelemetry」では何ができますか?

特定のプラットフォームに依存しないOpenTelemetryリファレンスです。シグナルの選択(traces/metrics/logs)、スパンの設計、コンテキスト伝播(W3C TraceContext)、サンプリング戦略、OTLPエクスポーターの設定を扱います。設計上の判断を適切に行うため、OTelの計装コードを書く前に使います。プラットフォーム固有のスキル(otel-node、cloudflare-workers-otel-utels)は、このスキルを基盤として追加の内容を提供します。

TypingMindでOpentelemetryを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Opentelemetryはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにOpentelemetryをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/mizchi/skills/tree/main/opentelemetryを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Opentelemetryを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Opentelemetryで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもOpentelemetryを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Opentelemetry」は無料ですか?

mizchiがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇