All Articles/Logging

Adding Metadata and Tags to Logs

Enrich your logs with structured metadata and searchable tags.


Metadata

Metadata is a key-value object attached to a log entry. Use it for any structured data you want to search or filter on later.

JavaScript
Lognitor.info('Order shipped', {
  metadata: {
    orderId: 'ord_456',
    customerId: 'cust_789',
    total: 149.99,
    items: 3,
    shippingMethod: 'express',
  },
});

In the dashboard, you can search logs by metadata values and see them in the log detail panel.

Tags

Tags are string labels that categorize logs. Use them for cross-cutting concerns.

JavaScript
Lognitor.info('Payment processed', {
  metadata: { gateway: 'stripe', amount: 99.99 },
  tags: ['payment', 'revenue', 'critical-path'],
});

You can filter logs by tag in the dashboard's advanced filters.

Global Context

Use setContext() to add metadata to every log automatically:

JavaScript
Lognitor.setContext({ region: 'us-east-1', deployId: 'deploy_456' });
Lognitor.setTags(['production']);

// Every log now includes region, deployId, and the production tag
Lognitor.info('Request processed');
Consistent naming

Use consistent field names across all services. If your API logs userId but your worker logs user_id, searching becomes difficult.