شعار Matlab Instrument Opentelemetry Tracing

Matlab Instrument Opentelemetry Tracing

مؤسسةشائع
matlab
matlab-instrument-opentelemetry-tracing

Add OpenTelemetry tracing to MATLAB code. Use when the user asks to "add tracing", "instrument with spans", "add OpenTelemetry", "trace my code", "add observability" (when about tracing), or mentions "spans", "distributed tracing", or "OTel tracing" in the context of MATLAB functions. Covers span creation, parent-child context propagation, error handling, attributes, events, and semantic conventions.

نظرة عامة

الناشرmatlab
المستودعmatlab-agentic-toolkit
اسم المهارةmatlab-instrument-opentelemetry-tracing
النجوم
1.2K
التفريعات
138
الملفات المرفقة
2
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 2

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها matlab على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Matlab Instrument Opentelemetry Tracing في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/matlab-software-development/matlab-instrument-opentelemetry-tracing
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/matlab-software-development/matlab-instrument-opentelemetry-tracing .claude/skills/matlab-instrument-opentelemetry-tracing
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Matlab Instrument Opentelemetry Tracing في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Matlab Instrument Opentelemetry Tracing تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Matlab Instrument Opentelemetry Tracing بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Instrument MATLAB Code with OpenTelemetry Tracing

Add OpenTelemetry tracing spans to MATLAB functions with correct implicit context propagation, RAII lifecycle, and semantic conventions.

Prerequisites

The OpenTelemetry-MATLAB package (Version 1.11.0 or newer) must be installed. It provides the opentelemetry.trace.* namespace used throughout this skill. Requires MATLAB R2022b or newer.

Key Functions

FunctionPurposeToolboxAvailable From
opentelemetry.trace.getTracerObtain a tracer instance by nameOpenTelemetry-MATLABR2022b
startSpanCreate a new span from a tracerOpenTelemetry-MATLABR2022b
makeCurrentSet span as current context (enables implicit parent-child)OpenTelemetry-MATLABR2022b
setAttributesAttach key-value metadata to a spanOpenTelemetry-MATLABR2022b
setStatusMark span as "Ok" or "Error"OpenTelemetry-MATLABR2022b
recordExceptionRecord an MException on a spanOpenTelemetry-MATLABR2022b
addEventRecord a timestamped event within a spanOpenTelemetry-MATLABR2022b
endSpanEnd a span mid-function (loops only)OpenTelemetry-MATLABR2022b

MATLAB API Differences

The MATLAB OpenTelemetry API differs slightly from C++, Java, and Python implementations. Do not rely on general OTel knowledge from other languages — when unsure about a function, use help opentelemetry.trace.Span or similar to check what exists. Common traps:

  • setAttribute (singular) does not exist — use setAttributes (plural)
  • opentelemetry.trace.StatusCode.Ok / StatusCode.Error enums do not exist — pass the strings "Ok" or "Error" directly to setStatus

When to Use

  • User asks to add tracing or spans to MATLAB code
  • User asks to instrument code with OpenTelemetry
  • User asks to add observability and tracing is part of the request
  • User wants parent-child span relationships across functions

When NOT to Use

  • User wants metrics only (counters, histograms, gauges) — no tracing skill needed
  • User wants logging only (structured log records) — no tracing skill needed
  • User wants to configure the TracerProvider/SDK (exporters, samplers, resource) — that belongs in a separate setup script
  • User wants to propagate context across network boundaries (inject/extract into HTTP headers)
  • User wants to instrument inside parfor loops — OTel context is not thread-safe in MATLAB

Absolute Rules

These rules override all other considerations. Violating any of them produces incorrect instrumentation.

1. Never modify function signatures

Instrumentation must be invisible to callers. Never add parameters (tracer, context, span) to a function. Never change return values. Each function obtains its own tracer internally:

matlab
tr = opentelemetry.trace.getTracer("tracer_name");

This is a cheap lookup from the global provider, not a resource allocation.

2. Spans are RAII — never call endSpan at function exit

The MATLAB Span object holds a C++ shared pointer. When the span variable goes out of scope (function returns, error thrown), the C++ destructor automatically ends the span. Only call endSpan when you need to end a span mid-function before the variable naturally goes out of scope.

3. Scope is RAII — never call clear(scope) at function exit

The Scope object returned by makeCurrent restores the previous context when it goes out of scope. Assign it to a variable to control its lifetime. The %#ok<NASGU> pragma suppresses the "unused variable" warning because the variable's lifetime is its purpose, not its value. Exception: inside loops, clear is required to restore the parent context before the next iteration (see loop pattern).

4. Always call makeCurrent on every span

Every span must be made current so child spans created in called functions automatically become children. Without makeCurrent, child spans become orphaned root spans.

5. Never pass explicit "Context" to startSpan

When makeCurrent is used consistently, startSpan automatically picks up the current span as parent. Passing "Context" explicitly is redundant and error-prone. The only exception is when creating a span that must be a child of a different span than the current one (rare).

6. Always set span status

Every span must have its status set before it ends:

  • setStatus(span, "Ok") on the success path
  • setStatus(span, "Error", message) on the failure path

A span without explicit status is ambiguous in trace viewers.

7. Use getTracer directly

matlab
tr = opentelemetry.trace.getTracer("tracer_name");

Never use opentelemetry.sdk.trace.TracerProvider() or opentelemetry.trace.Provider.getTracerProvider() followed by getTracer. The one-liner above is the correct entry point.

8. Use snake_case attribute names with meaningful domain nouns

All attribute names must be lowercase, dot-separated, and use snake_case within each component. The namespace (left of the dot) must be a meaningful domain noun — not a generic word like "total", "numeric", or "count". See the Semantic Conventions section below for the full pattern and examples.

Workflow

Step 1: Analyze the code

Identify:

  • Entry-point function (top-level function the user calls)
  • Sub-functions and local functions that represent distinct units of work
  • I/O operations (file read/write, network calls, database)
  • Error-prone sections (file I/O, external systems, parsing)
  • Computationally significant operations worth tracking

Step 2: Choose a tracer name

Derive from the file name or containing package:

  • processSensorData.m → "processSensorData"
  • +mypackage/analyze.m → "mypackage"

All functions in the same workflow should share the same tracer name.

Step 3: Instrument each function

Apply the core pattern to every function that represents a meaningful unit of work. Do not instrument trivial helpers (< 5 lines, no I/O) or functions called thousands of times in tight loops.

Step 4: Add error handling where needed

Add try-catch with recordException only for functions that perform I/O or call external systems. Do not add try-catch around pure computation.

Step 5: Add attributes and events

Add attributes that would help with debugging: input sizes, key parameters, output characteristics. Record events for significant milestones. Follow semantic conventions (see references/semantic-conventions.md).

Step 6: Verify

Run the instrumented code via mcp__matlab__evaluate_matlab_code or mcp__matlab__run_matlab_file to confirm it executes without error.

Core Pattern

This is the one correct pattern for every instrumented function:

matlab
function result = processData(inputData, method)
    tr = opentelemetry.trace.getTracer("myService");
    span = startSpan(tr, "processData");
    scope = makeCurrent(span); %#ok<NASGU>

    % --- original function body (unchanged) ---
    result = transform(inputData, method);

    setStatus(span, "Ok");
end

Key points:

  • getTracer inside the function — never passed as argument
  • startSpan with no "Context" — inherits from current context automatically
  • scope = makeCurrent(span) — makes this span the parent for any child spans
  • %#ok<NASGU> — suppresses false warning; scope lifetime is the point
  • setStatus before the function returns
  • No endSpan — span ends via RAII when function returns

Multi-function example

matlab
function results = runPipeline(inputFile)
    tr = opentelemetry.trace.getTracer("pipeline");
    span = startSpan(tr, "runPipeline");
    scope = makeCurrent(span); %#ok<NASGU>

    data = loadData(inputFile);
    cleaned = cleanData(data);
    results = analyze(cleaned);

    setStatus(span, "Ok");
end

function data = loadData(filepath)
    tr = opentelemetry.trace.getTracer("pipeline");
    span = startSpan(tr, "loadData");
    scope = makeCurrent(span); %#ok<NASGU>

    data = readtable(filepath);

    setStatus(span, "Ok");
end

function cleaned = cleanData(data)
    tr = opentelemetry.trace.getTracer("pipeline");
    span = startSpan(tr, "cleanData");
    scope = makeCurrent(span); %#ok<NASGU>

    cleaned = rmmissing(data);

    setStatus(span, "Ok");
end

function results = analyze(data)
    tr = opentelemetry.trace.getTracer("pipeline");
    span = startSpan(tr, "analyze");
    scope = makeCurrent(span); %#ok<NASGU>

    results = summary(data);

    setStatus(span, "Ok");
end

Each function independently obtains a tracer and creates its own span. Parent-child relationships are established automatically through makeCurrent.

Error Handling Pattern

Use for functions with I/O or external system calls:

matlab
function data = fetchData(url)
    tr = opentelemetry.trace.getTracer("myService");
    span = startSpan(tr, "fetchData", SpanKind="client");
    scope = makeCurrent(span); %#ok<NASGU>
    setAttributes(span, "url.full", url);

    try
        data = webread(url);
        setAttributes(span, "http.response.status_code", 200);
    catch ME
        recordException(span, ME);
        setStatus(span, "Error", ME.message);
        rethrow(ME);
    end

    setStatus(span, "Ok");
end

Key points:

  • recordException captures the full MException (identifier, message, stack trace, cause)
  • setStatus(span, "Error", ...) marks the span as errored in trace viewers
  • rethrow(ME) preserves the original error — span still ends via RAII after rethrow
  • Both recordException and setStatus are needed: one records detail, the other sets the visual indicator
  • setStatus(span, "Ok") goes after the try-catch block, not inside try — rethrow exits the function so "Ok" is only reached on success

Attributes

Set attributes with setAttributes (plural, never singular setAttribute which does not exist):

matlab
setAttributes(span, "input.rows", height(data), "input.columns", width(data));

Or using a dictionary at span creation:

matlab
span = startSpan(tr, "processData", Attributes=dictionary( ...
    ["input.file", "input.format"], ...
    {filepath, "csv"}));

Numeric values do not need type casting — the API handles all MATLAB numeric types natively.

Events

Record events for significant milestones within a span:

matlab
addEvent(span, "validationComplete", "rows.valid", validCount, "rows.rejected", rejectCount);

SpanKind

Set SpanKind only when the operation involves remote communication. Do not set it for internal operations (the default is "internal").

SpanKindWhenMATLAB examples
"client"Outgoing request awaiting responsewebread, webwrite, ftp, database queries
"server"Handling an incoming requestMATLAB Production Server handler
"producer"Initiating work without waitingPublishing to a queue, enqueuing a batch job
"consumer"Processing work from a producerQueue listener, batch worker
matlab
span = startSpan(tr, "fetchData", SpanKind="client");

When to Use endSpan

Only use endSpan when ending a span mid-function — before the variable would naturally go out of scope:

matlab
function results = batchProcess(items)
    tr = opentelemetry.trace.getTracer("myService");
    span = startSpan(tr, "batchProcess");
    scope = makeCurrent(span); %#ok<NASGU>

    results = cell(numel(items), 1);
    for i = 1:numel(items)
        itemSpan = startSpan(tr, "processItem");
        itemScope = makeCurrent(itemSpan); %#ok<NASGU>
        setAttributes(itemSpan, "item.index", i);
        results{i} = processOne(items{i});
        setStatus(itemSpan, "Ok");
        endSpan(itemSpan);  % Needed: itemSpan must end each iteration
        clear("itemScope");  % Needed: restore parent context before next iteration
    end

    setStatus(span, "Ok");
end

Both lines at the end of the loop body are mandatory:

  • endSpan(itemSpan) — ends the span's timing. Without it, the span duration extends until the variable is overwritten on the next iteration (wrong timing).
  • clear("itemScope") — restores the parent span as the current context. Without it, makeCurrent on the next iteration would make the new span a child of the previous iteration's span (nested chain) instead of a sibling under the parent (correct flat list).

Semantic Conventions

Attribute names must follow the {object}.{property} pattern:

  • Lowercase and dot-separated — never camelCase
  • snake_case within each component — total_paths not totalPaths
  • Namespace is a meaningful domain noun — the word left of the dot must be a concrete object in the domain (e.g., batch, file, result, data), not a generic adjective or quantifier (total, numeric, count)
WrongRightWhy
batch.totalPathsbatch.total_pathssnake_case, not camelCase
option.S0option.initial_pricedescriptive, lowercase
numeric.columnsdata.numeric_columns"data" is meaningful domain noun; "numeric" is not
total.pathsresult.total_paths"total" is not a domain noun

See references/semantic-conventions.md for full guidance on code attributes, file I/O attributes, HTTP client attributes, and domain-specific patterns.

Common Mistakes

MistakeWhy it's wrongCorrect approach
Pass tracer as function argumentModifies the function API; breaks existing callersCall getTracer inside each function
Pass context as function argumentModifies the function API; makes instrumentation visibleUse makeCurrent — child spans inherit automatically
Call endSpan at function exitRedundant — span ends via RAII; adds noiseRemove it; only use endSpan mid-function
Call clear(scope) at function exitRedundant — scope restores context via RAII when function returnsRemove it; let the variable go out of scope. Inside loops, clear IS required — see loop pattern above
Pass "Context" to startSpanRedundant when makeCurrent is used; explicit couplingOmit it; startSpan uses current context
Omit makeCurrent in child functionGrandchild spans won't inherit context; breaks deep tracesAlways call makeCurrent on every span
Use setAttribute (singular)Does not exist in MATLAB OTel APIUse setAttributes (plural)
Omit setStatusSpan status is ambiguous in trace viewerAlways set "Ok" or "Error"
Wrap OTel code in if isConfiguredUnnecessary — OTel methods are no-ops when not configuredRemove the guard; instrument unconditionally
Use TracerProvider() then getTracerIndirect; extra line of code for no benefitUse opentelemetry.trace.getTracer(name) directly
Cast attributes to int64Unnecessary — API handles all MATLAB numeric typesUse native types as-is

What NOT to Instrument

  • Trivial helper functions (< 5 lines, no I/O)
  • Functions called thousands of times in tight loops (overhead)
  • Anonymous functions or callbacks (unless significant work)
  • Code inside parfor blocks (context is not thread-safe)

Copyright 2026 The MathWorks, Inc.


الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Matlab Instrument Opentelemetry Tracing؟

Add OpenTelemetry tracing to MATLAB code. Use when the user asks to "add tracing", "instrument with spans", "add OpenTelemetry", "trace my code", "add observability" (when about tracing), or mentions "spans", "distributed tracing", or "OTel tracing" in the context of MATLAB functions. Covers span creation, parent-child context propagation, error handling, attributes, events, and semantic conventions.

لماذا تستخدم Matlab Instrument Opentelemetry Tracing على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Matlab Instrument Opentelemetry Tracing عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Matlab Instrument Opentelemetry Tracing في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/matlab-software-development/matlab-instrument-opentelemetry-tracing. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Matlab Instrument Opentelemetry Tracing؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Matlab Instrument Opentelemetry Tracing؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Matlab Instrument Opentelemetry Tracing معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Matlab Instrument Opentelemetry Tracing مجانية؟

نشرها matlab على GitHub. راجع المستودع للاطلاع على شروط الترخيص. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇