Skip to content

altrupets/monorepo / skills/system-reliability-engineering/observability-stack

observability-stack

Unverified

scripts/nodejs/userService.js

View on GitHub
/**
 * Example User Service with Custom Spans
 *
 * Example service demonstrating custom spans and tracing.
 *
 * Usage:
 *   const { getUserById } = require('./userService');
 *   const user = await getUserById('123');
 */

const { trace } = require('@opentelemetry/api');
const { SpanStatusCode } = require('@opentelemetry/api');

const tracer = trace.getTracer('user-service');

/**
 * Get user by ID with custom span.
 *
 * @param {string} userId - User ID
 * @returns {Promise<Object>} User object
 */
async function getUserById(userId) {
  const span = tracer.startSpan('getUserById', {
    attributes: {
      'user.id': userId,
      'operation.type': 'read',
    },
  });

  try {
    span.addEvent('Fetching user from database');

    // Simulate database query
    const user = await fetchUserFromDatabase(userId);

    span.setAttribute('user.found', !!user);
    span.setStatus({ code: SpanStatusCode.OK });

    return user;
  } catch (error) {
    span.setStatus({
      code: SpanStatusCode.ERROR,
      message: error.message,
    });
    span.recordException(error);
    throw error;
  } finally {
    span.end();
  }
}

/**
 * Simulated database query.
 *
 * @param {string} userId - User ID
 * @returns {Promise<Object>} User object
 */
async function fetchUserFromDatabase(userId) {
  // Simulate async database operation
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        id: userId,
        name: 'John Doe',
        email: 'john@example.com',
      });
    }, 100);
  });
}

module.exports = {
  getUserById,
};
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 193kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 193kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 193kUpdated Claude CodeCodexVerifiedInstall