# Class TraceManager

java.lang.Object
com.google.adk.plugins.agentanalytics.TraceManager

public final class TraceManager extends Object
Manages OpenTelemetry-style trace and span context using InvocationContext callback data.

Uses a stack of SpanRecord objects to keep span, ID, ownership, and timing in sync.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `attachCurrentSpan()`
  `void`
  `clearStack()`
  `void`
  `ensureInvocationSpan(InvocationContext context)`
  `com.google.adk.plugins.agentanalytics.TraceManager.SpanIds`
  `getCurrentSpanAndParent()`
  `Optional<String>`
  `getCurrentSpanId()`
  `Optional<Instant>`
  `getFirstTokenTime(String spanId)`
  `String`
  `getRootAgentName()`
  `Optional<Instant>`
  `getStartTime(String spanId)`
  `String`
  `getTraceId(InvocationContext context)`
  `boolean`
  `hasAmbientSpan()`
  `void`
  `initTrace(InvocationContext context)`
  `Optional<com.google.adk.plugins.agentanalytics.TraceManager.RecordData>`
  `popSpan()`
  `String`
  `pushSpan(String spanName)`
  `void`
  `recordFirstToken(String spanId)`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getRootAgentName

    public String getRootAgentName()

  - ### initTrace

    public void initTrace(InvocationContext context)

  - ### getTraceId

    public String getTraceId(InvocationContext context)

  - ### hasAmbientSpan

    public boolean hasAmbientSpan()

  - ### pushSpan

    @CanIgnoreReturnValue public String pushSpan(String spanName)

  - ### attachCurrentSpan

    @CanIgnoreReturnValue public String attachCurrentSpan()

  - ### ensureInvocationSpan

    public void ensureInvocationSpan(InvocationContext context)

  - ### popSpan

    @CanIgnoreReturnValue public Optional<com.google.adk.plugins.agentanalytics.TraceManager.RecordData> popSpan()

  - ### clearStack

    public void clearStack()

  - ### getCurrentSpanAndParent

    public com.google.adk.plugins.agentanalytics.TraceManager.SpanIds getCurrentSpanAndParent()

  - ### getCurrentSpanId

    public Optional<String> getCurrentSpanId()

  - ### recordFirstToken

    public void recordFirstToken(String spanId)

  - ### getStartTime

    public Optional<Instant> getStartTime(String spanId)

  - ### getFirstTokenTime

    public Optional<Instant> getFirstTokenTime(String spanId)