Skip to content

Instantly share code, notes, and snippets.

@arun0009
Created February 20, 2026 07:31
Show Gist options
  • Select an option

  • Save arun0009/01ee57fa933e9bfbc8bde45782423fa6 to your computer and use it in GitHub Desktop.

Select an option

Save arun0009/01ee57fa933e9bfbc8bde45782423fa6 to your computer and use it in GitHub Desktop.

πŸ“ Minimal Professional Microservice Logging Standard (OTel-Compliant)

Field Type Required Notes / Spec Spec Link
timestamp string (ISO 8601) βœ… Log event time Logs Data Model
severity_text string βœ… Human-readable severity (e.g., INFO, ERROR) Logs Data Model
severity_number int βœ… Numeric severity Logs Data Model
trace_id string βœ… if trace available Correlates log to trace Trace Context in Logs
span_id string βœ… if trace available Correlates log to span Trace Context in Logs
body string or object βœ… Official log message field in OTel Logs Data Model
attributes map βœ… Container for semantic attributes Logs Data Model

πŸ”Ή Recommended Semantic Attributes (dot notation)

Attribute Type Required / Optional Notes Spec Link
service.name string βœ… Name of the microservice Resource Semantic Conventions
service.version string βœ… Microservice version Resource Semantic Conventions
deployment.environment string βœ… e.g., production, staging Resource Semantic Conventions
http.method string Conditional HTTP request method HTTP Semantic Conventions
http.status_code int Conditional HTTP response status HTTP Semantic Conventions
db.system string Conditional e.g., postgres, mysql DB Semantic Conventions
db.statement string Conditional SQL query or statement DB Semantic Conventions
messaging.system string Conditional e.g., kafka, rabbitmq Messaging Semantic Conventions
messaging.destination string Conditional Topic / queue name Messaging Semantic Conventions

πŸ”Ή Optional / Log-Specific Attributes

Attribute Notes Spec Link
log.record.uid Unique ID for log record Logs Semantic Conventions
log.record.original Original log string if transformed Logs Semantic Conventions
log.file.name File name of source Logs Semantic Conventions
log.iostream stdin / stdout / stderr Logs Semantic Conventions

⚠️ Naming Rules & Notes

Trace/Span IDs β†’ use underscore (trace_id, span_id) β€” official spec.

Message content β†’ use body for OTel compliance. Can map to message for developer familiarity.

Semantic attributes β†’ use dot notation (service.name, http.method).

Logs may include structured payloads in body (JSON object), not just strings.

βœ… Example Log JSON (OTel Compliant)

{
  "timestamp": "2026-02-19T10:00:00.000Z",
  "severity_text": "ERROR",
  "severity_number": 17,
  "body": "User login failed",
  "trace_id": "5b8efff798038103d269b633813fc60c",
  "span_id": "eee19b7ec3c1b174",
  "attributes": {
    "service.name": "auth-service",
    "service.version": "1.0.3",
    "deployment.environment": "production",
    "http.method": "POST",
    "http.status_code": 401,
    "user.email": "john.doe@example.com",
    "auth.attempts": 3
  }
}

This gives you a full, spec-citable logging contract. It answers your body vs message and trace_id vs trace.id questions with direct links to the official OpenTelemetry docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment