Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ENHANCEMENT] Add structured logging with correlation IDs for agent workflows #191

Open
Labels
enhancementNew feature or requesthelp wantedExtra attention is needed
@harikapadia999

Description

@harikapadia999

Problem

Current logging makes it difficult to:

  • Track requests across multiple agents
  • Debug complex multi-agent workflows
  • Correlate logs from different components
  • Analyze agent performance

Proposed Solution

Implement structured logging with correlation IDs:

# flo_ai/logging/structured.pyimportloggingimportuuidfromcontextvarsimportContextVarfromtypingimportOptional,Dict,Any# Context variable for correlation IDcorrelation_id:ContextVar[Optional[str]]=ContextVar('correlation_id',default=None)classStructuredLogger:def__init__(self,name:str):self.logger=logging.getLogger(name)self.name=namedef_add_context(self,extra:Dict[str,Any])->Dict[str,Any]:"""Add correlation ID and other context to log"""context= {'correlation_id':correlation_id.get(),'logger_name':self.name,**extra        }return {k:vfork,vincontext.items()ifvisnotNone}definfo(self,message:str,**kwargs):self.logger.info(message,extra=self._add_context(kwargs))defwarning(self,message:str,**kwargs):self.logger.warning(message,extra=self._add_context(kwargs))deferror(self,message:str,**kwargs):self.logger.error(message,extra=self._add_context(kwargs))# Usage in agentclassAgent:def__init__(self,name:str):self.logger=StructuredLogger(f"agent.{name}")defrun(self,input:str)->str:# Generate correlation ID for this requestcorr_id=str(uuid.uuid4())correlation_id.set(corr_id)self.logger.info("Agent started",agent_name=self.name,input_length=len(input)        )# ... agent logic ...self.logger.info("Agent completed",agent_name=self.name,duration_ms=duration        )

Log Output Format

JSON Format (for production):

{"timestamp":"2025-12-16T06:45:00Z","level":"INFO","message":"Agent started","correlation_id":"a1b2c3d4-e5f6-7890-abcd-ef1234567890","logger_name":"agent.customer_support","agent_name":"customer_support","input_length":150}

Human-Readable Format (for development):

2025-12-16 06:45:00 [INFO] [a1b2c3d4] agent.customer_support: Agent started (input_length=150)

Benefits

  1. ✅ Easy request tracing across components
  2. ✅ Better debugging of multi-agent workflows
  3. ✅ Performance analysis per correlation ID
  4. ✅ Integration with log aggregation tools (ELK, Datadog)
  5. ✅ Compliance and audit trails

Configuration

logging:format:"json"# or "human"level:"INFO"correlation_id:enabled:trueheader_name:"X-Correlation-ID"# For HTTP requestsfields:    -agent_name    -workflow_name    -user_id

Implementation Checklist

  • Create structured logger class
  • Add correlation ID context management
  • Integrate with all agents and workflows
  • Add JSON formatter for production
  • Add human-readable formatter for development
  • Update documentation
  • Add examples for log analysis

Related Tools

  • ELK Stack (Elasticsearch, Logstash, Kibana)
  • Datadog
  • Splunk
  • CloudWatch Logs Insights

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp