Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/obsidian-observability

@0d57af8
Run it yourself

Implement structured logging, metrics, error tracking, and a debug panel for Obsidian plugins. Use when adding debug logging, tracking plugin performance, building a diagnostics view, or setting up error reporting. Trigger with phrases like "obsidian logging", "obsidian monitoring", "obsidian debug panel", "track obsidian plugin performance".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/obsidian-observability

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesimplementation.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Obsidian Observability - Implementation Details

Structured Logger

type LogLevel = 'debug' | 'info' | 'warn' | 'error';

export class Logger {
  private pluginId: string;
  private level: LogLevel;
  private history: LogEntry[] = [];
  private maxHistory = 100;
  private readonly levelPriority = { debug: 0, info: 1, warn: 2, error: 3 };

  constructor(pluginId: string, level: LogLevel = 'info') {
    this.pluginId = pluginId;
    this.level = level;
  }

  debug(message: string, context?: Record<string, any>): void { this.log('debug', message, context); }
  info(message: string, context?: Record<string, any>): void { this.log('info', message, context); }
  warn(message: string, context?: Record<string, any>): void { this.log('warn', message, context); }
  error(message: string, error?: Error, context?: Record<string, any>): void {
    const errorContext = error ? { ...context, error: { name: error.name, message: error.message, stack: error.stack } } : context;
    this.log('error', message, errorContext);
  }

  time(label: string): () => void {
    const start = performance.now();
    return () => {
      const duration = performance.now() - start;
      this.history.push({ timestamp: new Date().toISOString(), level: 'debug', message: label, duration });
    };
  }

  exportLogs(): string {
    return this.history.map(e => {
      let line = `${e.timestamp} [${e.level}] ${e.message}`;
      if (e.duration) line += ` (${e.duration}ms)`;
      return line;
    }).join('\n');
  }
}

Metrics Collector

export class MetricsCollector {
  private counters = new Map<string, number>();
  private gauges = new Map<string, number>();
  private timers = new Map<string, { value: number; timestamp: number }[]>();

  increment(name: string, value = 1): void {
    this.counters.set(name, (this.counters.get(name) || 0) + value);
  }

  setGauge(name: string, value: number): void { this.gauges.set(name, value); }

  recordTiming(name: string, durationMs: number): void {
    const timings = this.timers.get(name) || [];
    timings.push({ value: durationMs, timestamp: Date.now() });
    while (timings.length > 100) timings.shift();
    this.timers.set(name, timings);
  }

  async timeAsync<T>(name: string, fn: () => Promise<T>): Promise<T> {
    const start = performance.now();
    try { return await fn(); }
    finally { this.recordTiming(name, performance.now() - start); }
  }

  getTimerStats(name: string) {
    const timings = this.timers.get(name);
    if (!timings?.length) return null;
    const values = timings.map(t => t.value).sort((a, b) => a - b);
    const sum = values.reduce((a, b) => a + b, 0);
    return {
      count: values.length, avg: sum / values.length,
      min: values[0], max: values[values.length - 1],
      p95: values[Math.floor(values.length * 0.95)],
    };
  }
}

Error Tracker

export class ErrorTracker {
  private errors = new Map<string, TrackedError>();

  track(error: Error, context: Record<string, any> = {}): void {
    const key = `${error.name}:${error.message}`;
    const existing = this.errors.get(key);
    if (existing) { existing.count++; existing.timestamp = new Date().toISOString(); }
    else {
      if (this.errors.size >= 50) this.errors.delete(this.errors.keys().next().value);
      this.errors.set(key, {
        timestamp: new Date().toISOString(),
        error: { name: error.name, message: error.message, stack: error.stack },
        context, count: 1,
      });
    }
  }

  getMostCommon(limit = 5) {
    return Array.from(this.errors.values()).sort((a, b) => b.count - a.count).slice(0, limit);
  }

  wrapAsync<T>(fn: () => Promise<T>, context = {}): Promise<T> {
    return fn().catch((error: Error) => { this.track(error, context); throw error; });
  }
}

Debug Panel View

export class DebugView extends ItemView {
  async onOpen() {
    const container = this.containerEl.children[1];
    this.render(container);
    this.refreshInterval = window.setInterval(() => this.render(container), 5000);
  }

  private render(container: Element) {
    container.empty();
    // Render: Metrics (counters, timer stats), Recent Errors (top 5), Recent Logs (last 10)
    // Export button: downloads JSON with metrics + errors + logs
    // Clear button: resets all data
  }

  private exportDebugData() {
    const data = {
      timestamp: new Date().toISOString(),
      plugin: this.plugin.manifest.id,
      version: this.plugin.manifest.version,
      metrics: this.plugin.metrics.getAllMetrics(),
      errors: this.plugin.errorTracker.getErrors(),
      logs: this.plugin.logger.exportLogs(),
    };
    // Create downloadable JSON blob
  }
}

Debug View Styles

.plugin-debug-view { padding: 16px; }
.debug-section { margin-bottom: 24px; padding: 12px; background: var(--background-secondary); border-radius: 4px; }
.log-output { font-family: monospace; font-size: 12px; max-height: 200px; overflow-y: auto; }
.log-debug { color: var(--text-muted); }
.log-warn { color: var(--text-warning); }
.log-error { color: var(--text-error); }

Plugin Integration Example

export default class MyPlugin extends Plugin {
  logger: Logger;
  metrics: MetricsCollector;
  errorTracker: ErrorTracker;

  async onload() {
    this.logger = new Logger(this.manifest.id, 'debug');
    this.metrics = new MetricsCollector();
    this.errorTracker = new ErrorTracker();

    const endLoadTime = this.logger.time('plugin-load');

    this.addCommand({
      id: 'my-command', name: 'My Command',
      callback: async () => {
        this.metrics.increment('command.my-command');
        await this.metrics.timeAsync('command.duration', async () => { /* impl */ });
      },
    });

    endLoadTime();
    this.logger.info('Plugin loaded');
  }
}

Tons of Skills by Intent Solutions | jeremylongshore.com

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides a production-ready template for implementing observability features in Obsidian plugins, including logging, metrics collection, and error tracking. The implementation follows best practices, uses built-in Obsidian APIs, and ensures that diagnostic data is only exported via manual user action to the clipboard. No malicious patterns or security risks were identified.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 months ago
What it can do
Reads files Edits files Runs commands
version
1.13.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
tags
[
  "obsidian",
  "monitoring",
  "debugging",
  "performance",
  "logging"
]
All 4 allowed tools
ReadWriteEditBash(npm:*)
Other metadata
compatibility
Designed for Claude Code

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/obsidian-observability