Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

opentelemetry-trace-assertions

БесплатноБез исполняемых скриптовНе проверен

Use when a service is instrumented with OpenTelemetry and alerts, SLOs or dashboards depend on span names or attributes a refactor could drop. Captures spans…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

opentelemetry-trace-assertions

Overview

Tests capture the spans the code under test emits with an in-memory exporter, then assert the contract that alerts, SLOs and dashboards read: span names, attribute keys and values, status, kind, and which span is whose parent. A refactor that drops any of these stays green in ordinary tests and silently empties a panel or stops an alert.

When to use

  • Alerts, SLO queries or dashboards select on span names or attributes.
  • A trace-shape change has already caused a missed page or an empty panel.
  • New instrumentation needs a regression baseline.

Step 1 - Install the SDK test pieces

Language Install
Python pip install opentelemetry-sdk
JS / TS npm install -D @opentelemetry/sdk-trace-base @opentelemetry/sdk-trace-node @opentelemetry/api
Java io.opentelemetry:opentelemetry-sdk-testing (test scope)
.NET dotnet add package OpenTelemetry.Exporter.InMemory

Step 2 - Wire a synchronous in-memory exporter

SimpleSpanProcessor passes each span to the exporter as it ends; the batching processor exports on a timer, so a read right after the exercise misses spans and tests start sleeping ([Python SDK export docs][py-export]).

# tests/conftest.py
import pytest
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter

_exporter = InMemorySpanExporter()
_provider = TracerProvider()
_provider.add_span_processor(SimpleSpanProcessor(_exporter))
trace.set_tracer_provider(_provider)        # once per process

@pytest.fixture
def spans():
    _exporter.clear()                        # each test sees only its own spans
    def by_name(name):
        found = [s for s in _exporter.get_finished_spans() if s.name == name]
        assert found, f"no finished span named {name!r}"
        return found[-1]
    yield by_name
    _exporter.clear()

Reach spans through by_name, never by index or by counting them: instrumentation order and extra spans change without the contract changing, and an empty buffer makes loops over spans pass vacuously.

Step 3 - Assert name, attributes, status and kind

from opentelemetry.trace import SpanKind, StatusCode

def test_order_create_span(spans):
    create_order(items=[item])

    order = spans("order.create")
    assert order.attributes["order.item_count"] == 1
    assert order.status.status_code != StatusCode.ERROR
    assert order.kind == SpanKind.INTERNAL

def test_rates_provider_down_is_an_error(spans, provider_down):
    price = convert(100, "EUR")              # falls back to the cached rate
    assert price == 8600                     # the conversion still succeeds

    fetch = spans("rates.fetch")
    assert fetch.kind == SpanKind.CLIENT     # an outgoing call, not in-process
    assert fetch.status.status_code == StatusCode.ERROR
    assert fetch.attributes["error.type"] == "ConnectionRefusedError"
    assert spans("pricing.convert").status.status_code != StatusCode.ERROR

Status rules for HTTP spans: leave status unset on 1xx-3xx and on server-side 4xx; set Error on client-side 4xx and on 5xx ([HTTP semantic conventions][semconv-http]). error.type is required when the call ended in an error. Only the failing span gets the error status; a caller that recovered keeps a successful one.

Step 4 - Assert parent-child structure

IDs are random per run, so compare IDs read from the same run, never literal values:

def test_db_span_is_child_of_order(spans):
    create_order(items=[item])
    order, db = spans("order.create"), spans("db.query")

    assert db.context.trace_id == order.context.trace_id
    assert db.parent is not None, "db.query started a new trace"
    assert db.parent.span_id == order.context.span_id

For context sent to another service, parse the outgoing traceparent header the fake client captured (00-<trace_id>-<span_id>-<flags>) and compare its trace and span IDs with the CLIENT span's own context.trace_id / context.span_id formatted as 32 and 16 hex digits ([W3C Trace Context][w3c]). A span for another service's work (inventory, a worker) cannot be proved here; do not create one in the test and assert on it.

Step 5 - Semantic-convention keys

HTTP client spans require http.request.method, url.full, server.address and server.port; http.response.status_code is required when a status was received and error.type when the call failed. The span name is {method}, or {method} {target} when a low-cardinality target is known ([HTTP semantic conventions][semconv-http]):

def test_charge_call_attributes(spans):
    charge_card(order)
    http = spans("POST")                     # "{method}" or "{method} {url.template}"
    assert http.kind == SpanKind.CLIENT
    assert http.attributes["http.request.method"] == "POST"
Полный SKILL.md на GitHub

Установить opentelemetry-trace-assertions в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.jsonevals/availability-panel-flat-at-100-through-an-outage/criteria.jsonevals/availability-panel-flat-at-100-through-an-outage/task.mdevals/card-outage-that-paged-nobody/criteria.jsonevals/card-outage-that-paged-nobody/task.mdevals/db-panel-empty-for-a-month-while-tests-stay-green/criteria.jsonevals/db-panel-empty-for-a-month-while-tests-stay-green/task.mdevals/three-acceptance-criteria-one-repo/criteria.jsonevals/three-acceptance-criteria-one-repo/task.mdevals/trace-job-eats-more-wall-clock-than-the-rest-of-ci/criteria.jsonevals/trace-job-eats-more-wall-clock-than-the-rest-of-ci/task.md

FAQ

Что делает скилл opentelemetry-trace-assertions?

Use when a service is instrumented with OpenTelemetry and alerts, SLOs or dashboards depend on span names or attributes a refactor could drop. Captures spans with the in-memory exporter in tests (Python, JS, Java) and asserts on names, attributes, status, kind and structure.

Как установить скилл opentelemetry-trace-assertions?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл opentelemetry-trace-assertions запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить opentelemetry-trace-assertions с