Potencia el registro de Go con slog-context: Registro contextual fácil

Descubre slog-context, una librería de Go que integra slog con context: guarda loggers y atributos contextuales y añade trace IDs, span IDs y OpenTelemetry para una observabilidad mejorada.

20 sept 2025 • 2 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Resumen rápido: slog-context es una librería para Go que facilita la integración entre el registro estructurado slog y el paquete context. Permite almacenar y recuperar loggers desde el contexto, añadir atributos contextuales que se incorporan automáticamente a cada línea de registro y extraer valores personalizados como TraceIDs de OpenTelemetry para enriquecer los logs.

Qué aporta: almacenar loggers directamente en el contexto para evitar pasar parámetros a cada función, añadir atributos contextuales que el manejador incorpora sin modificar las llamadas a logging, e integración con OpenTelemetry mediante el paquete slogotel para incluir trace y span IDs en los registros. También funciona con sloghttp para captar atributos desde middleware HTTP.

Flujos principales: puedes insertar un logger en el contexto y usar wrappers como With, Info o Error desde cualquier lugar de la aplicación; o bien añadir atributos al contexto que se anteponen o añaden automáticamente a las entradas de log. Esto simplifica el rastro de peticiones distribuidas y mejora la observabilidad sin cambiar toda la base de código.

Compatibilidad y flexibilidad: slog-context soporta tanto la interfaz estándar slog como la interfaz logr, con conversiones automáticas entre slog.Logger y logr.Logger para integrarse en proyectos existentes sin grandes refactors.

Beneficios: registros más consistentes y legibles, depuración más rápida, integración directa con herramientas de observabilidad y menos código repetitivo. Ideal para aplicaciones a escala que necesitan trazabilidad y contexto en cada log.

Estadísticas del proyecto: Stars 138 Forks 6 Open Issues 1.

En Q2BSTUDIO, empresa de desarrollo de software y aplicaciones a medida, aplicamos estas buenas prácticas de logging y observabilidad en proyectos reales, desde software a medida hasta soluciones cloud. Si necesitas desarrollar una aplicación personalizada con trazabilidad y monitoreo integrados visita servicios de desarrollo de aplicaciones y software a medida. Para arquitecturas en la nube y despliegues observables trabajamos con servicios cloud AWS y Azure que facilitan la integración con OpenTelemetry y sistemas centralizados de logs.

Servicios y palabras clave: aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA y power bi. En Q2BSTUDIO combinamos desarrollo a medida, inteligencia artificial y ciberseguridad para ofrecer soluciones completas que mejoran la observabilidad, el rendimiento y la seguridad de sus sistemas.

Conclusión: si buscas una forma práctica de potenciar el registro en Go y enriquecer tus logs con contexto y trazas, slog-context es una herramienta imprescindible. Integrarla reduce el esfuerzo de instrumentación y acelera la detección de problemas en entornos distribuidos, algo que aplicamos de forma habitual en nuestros proyectos de software a medida y arquitecturas cloud.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.