Semantic logging improves the way developers log information by using structured data instead of plain text. This makes logs easier to query, analyze, and correlate with other events. In modern applications, semantic logging is key for debugging and gaining deep insights into your app's behavior.
Semantic logging, also known as structured logging, means storing log data in a structured format like JSON. Unlike plain text logs, semantic logs are machine-readable and include key-value pairs for better context.
1console.log(JSON.stringify({ event: "user_login", userId: 123, timestamp: Date.now() }));
Plain text logs are difficult to search and filter without tooling like Otelic because they don’t have a consistent format. Semantic logs solve this by making data structured and queryable, which simplifies debugging and analysis. Otelic though provides free-form search in log messages.
Semantic logging helps developers and tools understand logs faster. It’s particularly useful in modern distributed systems where logs need to be correlated across services.
1console.log(JSON.stringify({ event: "db_query", query: "SELECT * FROM users", durationMs: 120, timestamp: Date.now() }));
Otelic.com fully supports semantic logs, allowing you to query and filter logs with powerful tools. By combining semantic logging with traces, Otelic makes it easier to debug complex issues and gain performance insights.
To get the most out of semantic logging, include relevant metadata in your logs, such as user IDs, timestamps, and request details. This ensures your logs are meaningful and actionable.
1console.log(JSON.stringify({
2 event: "user_action",
3 action: "purchase",
4 userId: 123,
5 amount: 99.99,
6 timestamp: Date.now()
7}));
With traces you would add these things as attributes.
1import { trace } from '@opentelemetry/api';
2
3const tracer = trace.getTracer('my-app');
4const span = tracer.startSpan('user_action');
5
6span.setAttributes({
7 event: "user_action",
8 action: "purchase",
9 userId: 123,
10 amount: 99.99,
11 timestamp: Date.now(),
12});
13
14span.end();