NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::observability::OpenInferenceTracerSession Class Reference

RAII session returned by openinference_tracer. More...

#include <openinference.h>

Public Member Functions

ChildSpanStarter child_span_starter () const
 Return a copied operation that opens a child while leasing the current parent through Tracer::start_span.
 
void close ()
 End the root span + any pending node spans.
 
Span * current_parent () const noexcept
 Snapshot of the current span.
 

Public Attributes

graph::GraphStreamCallback cb
 Engine event callback. Pass to engine.run_stream().
 

Friends

NEOGRAPH_API OpenInferenceTracerSession openinference_tracer (Tracer &, std::string, std::string)
 Open a CHAIN-kind root span and return a session whose cb opens per-node CHAIN child spans + LLM_TOKEN events under it.
 

Detailed Description

RAII session returned by openinference_tracer.

Holds the root span (kept alive for the duration of the engine run) and the GraphStreamCallback wired to record per-node / streaming events under that root.

Usage:

auto session = openinference_tracer(my_tracer);
engine.run_stream(cfg, session.cb);
session.close(); // ends the root + any straggler node spans
friend NEOGRAPH_API OpenInferenceTracerSession openinference_tracer(Tracer &, std::string, std::string)
Open a CHAIN-kind root span and return a session whose cb opens per-node CHAIN child spans + LLM_TOKE...

close() is also called by the destructor — explicit close is recommended only when the user wants to inspect the tracer's exported spans before the session goes out of scope (e.g. in tests). Double-close is a no-op. Copies of cb are safe to retain: they become no-ops after close/destruction, and close() waits for callbacks that already entered before finalizing their spans.

Definition at line 69 of file openinference.h.

Member Function Documentation

◆ child_span_starter()

ChildSpanStarter neograph::observability::OpenInferenceTracerSession::child_span_starter ( ) const

Return a copied operation that opens a child while leasing the current parent through Tracer::start_span.

Safe across close/destruction.

◆ close()

void neograph::observability::OpenInferenceTracerSession::close ( )

End the root span + any pending node spans.

Idempotent.

Warning
Adapter authors: close() resets the internal unique_ptr<Span> over the root span (and the corresponding pending-node-span stacks). If your Tracer adapter handed out raw pointers into caller-owned span storage and stored them for post-close inspection, those pointers become dangling — any walk of "all spans I've recorded" after close() reads freed memory and may crash, hang, or print garbage (issue #24).

The adapter must own the span DATA itself (not just the wrapper). Pattern: split a RecordedSpan (owned by the adapter in unique_ptrs) from the Span wrapper handed back to the OpenInference layer. The wrapper's destruction is then harmless — the recorded data lives in the adapter and survives close(). See tests/test_openinference_cpp.cpp (InMemoryTracer) and examples/49_openinference.cpp (PrintTracer) for the canonical shape.

◆ current_parent()

Span * neograph::observability::OpenInferenceTracerSession::current_parent ( ) const
noexcept

Snapshot of the current span.

The pointer is only valid until another session operation or close(); use child_span_starter() when opening a child concurrently with session teardown.

Friends And Related Symbol Documentation

◆ openinference_tracer

NEOGRAPH_API OpenInferenceTracerSession openinference_tracer ( Tracer &  ,
std::string  ,
std::string   
)
friend

Open a CHAIN-kind root span and return a session whose cb opens per-node CHAIN child spans + LLM_TOKEN events under it.

Parameters
tracerTracer adapter. Must outlive the session.
root_nameSpan name for the root (default "graph.run").
node_span_prefixPrefix for per-node spans (default "node.").

The documentation for this class was generated from the following file: