Skip to content

feat(server): API key authentication for collector (#130)#131

Merged
Siddhant-K-code merged 1 commit into
mainfrom
feat/130-collector-auth
May 24, 2026
Merged

feat(server): API key authentication for collector (#130)#131
Siddhant-K-code merged 1 commit into
mainfrom
feat/130-collector-auth

Conversation

@Siddhant-K-code

Copy link
Copy Markdown
Owner

What

Adds API key authentication to agent-strace server. Prerequisite for the hosted collector (#129).

Closes #130

Changes

Server side

  • agent-strace server keygen — generates a new ast_-prefixed key using secrets.token_hex(16)
  • agent-strace server --auth-key KEY — enforces Authorization: Bearer KEY on all endpoints; requests without it get 401
  • AGENT_STRACE_AUTH_KEY env var — alternative to --auth-key on the server
  • No --auth-key = current unauthenticated behaviour, unchanged

Client side

  • AGENT_STRACE_AUTH_KEY env var — when set, send_event_to_endpoint and send_session_meta_to_endpoint inject Authorization: Bearer automatically into all outbound requests to AGENT_STRACE_ENDPOINT
  • --stream-headers on watch already worked; no changes needed there

No new dependenciessecrets.token_hex is stdlib.

Tests

32 tests in tests/test_server_auth.py:

  • generate_api_key: prefix, length, hex suffix, uniqueness
  • _auth_headers: env var present/absent/empty
  • No-auth mode: all endpoints still work without a key
  • Auth mode, valid key: all endpoints return 200
  • Auth mode, missing key: all endpoints return 401 with JSON body
  • Auth mode, wrong key: wrong key / partial key / no Bearer prefix / empty Bearer all return 401
  • cmd_server keygen: returns 0, prints valid key, unique across calls
  • Client injection: send_event_to_endpoint and send_session_meta_to_endpoint fail without env key, succeed with it

Docs

  • docs/server.md: new Authentication section with keygen, --auth-key, AGENT_STRACE_AUTH_KEY, and --stream-headers examples
  • docs/commands.md: server flag table updated

- server keygen: prints a new ast_-prefixed key (secrets.token_hex)
- server --auth-key KEY: enforces Authorization: Bearer on all endpoints
- AGENT_STRACE_AUTH_KEY env var: auto-injected into all outbound
  collector requests (send_event_to_endpoint, send_session_meta_to_endpoint)
- No auth = current behaviour unchanged
- No new dependencies
- 32 tests in tests/test_server_auth.py
- docs/server.md: Authentication section
- docs/commands.md: server flag reference updated
- Version bump 0.51.1 → 0.52.0

Closes #130

Co-authored-by: Ona <no-reply@ona.com>
@Siddhant-K-code Siddhant-K-code merged commit b0c4d5f into main May 24, 2026
4 checks passed
@Siddhant-K-code Siddhant-K-code deleted the feat/130-collector-auth branch May 24, 2026 15:27
Siddhant-K-code added a commit that referenced this pull request May 31, 2026
- integrations/crewai.py: new integration patching Crew.kickoff,
  Agent.execute_task, and Task.execute_sync to emit session_start,
  llm_request/response, and tool_call/result events
- integrations/langchain.py: add LangGraph StateGraph.compile patch
  that wraps each compiled node with decision + tool_result events;
  uninstrument_langchain now properly restores all three patches
- integrations/__init__.py: register crewai and langgraph aliases,
  add instrument_crewai() export, add to _DETECTABLE/_FRAMEWORK_PROBE
- pyproject.toml: add crewai optional extra and include in all-integrations

Closes #131

Co-authored-by: Ona <no-reply@ona.com>
@Siddhant-K-code

Copy link
Copy Markdown
Owner Author

Fixed in #153, released in v0.56.0.

CrewAI: new integrations/crewai.py — patches Crew.kickoff, Agent.execute_task, Task.execute_sync. Enable with pip install agent-trace[crewai] then instrument_crewai() or AGENT_STRACE_AUTO_INSTRUMENT=crewai.

LangGraph: instrument_langchain() now also patches StateGraph.compile when langgraph is installed, wrapping each compiled node with decision + tool_result events for per-node latency visibility. Falls back silently if langgraph is absent.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: API key authentication for collector endpoints

1 participant