Class MongodbObservationContext

java.lang.Object
io.micrometer.observation.Observation.Context
io.micrometer.observation.transport.SenderContext<Object>
com.mongodb.observability.micrometer.MongodbObservationContext
All Implemented Interfaces:
io.micrometer.observation.Observation.ContextView

public class MongodbObservationContext extends io.micrometer.observation.transport.SenderContext<Object>
A MongoDB-specific SenderContext for Micrometer observations.

Extends SenderContext with Kind.CLIENT to preserve the client span kind in the tracing bridge. Provides a MongoDB-specific type that users can filter on when registering ObservationHandler or ObservationConvention instances.

Domain fields (commandName, databaseName, etc.) are populated by the driver after the observation is started and before it is stopped. The ObservationConvention reads these fields at stop time to produce the final tag key-values.

Since:
5.7
  • Constructor Details

    • MongodbObservationContext

      public MongodbObservationContext()
      Creates a new MongodbObservationContext with Kind.CLIENT kind.
  • Method Details

    • getCommandName

      @Nullable public String getCommandName()
      Returns:
      the command name, or null if not set
    • setCommandName

      public void setCommandName(@Nullable String commandName)
      Parameters:
      commandName - the command name
    • getDatabaseName

      @Nullable public String getDatabaseName()
      Returns:
      the database name, or null if not set
    • setDatabaseName

      public void setDatabaseName(@Nullable String databaseName)
      Parameters:
      databaseName - the database name
    • getCollectionName

      @Nullable public String getCollectionName()
      Returns:
      the collection name, or null if not set
    • setCollectionName

      public void setCollectionName(@Nullable String collectionName)
      Parameters:
      collectionName - the collection name
    • getServerAddress

      @Nullable public ServerAddress getServerAddress()
      Returns:
      the server address, or null if not set
    • setServerAddress

      public void setServerAddress(@Nullable ServerAddress serverAddress)
      Parameters:
      serverAddress - the server address
    • getConnectionId

      @Nullable public ConnectionId getConnectionId()
      Returns:
      the connection ID, or null if not set
    • setConnectionId

      public void setConnectionId(@Nullable ConnectionId connectionId)
      Parameters:
      connectionId - the connection ID
    • getObservationType

      @Nullable public MongodbObservation getObservationType()
      Returns:
      the observation type, or null if not set
    • setObservationType

      public void setObservationType(MongodbObservation observationType)
      Parameters:
      observationType - the observation type
    • getCursorId

      @Nullable public Long getCursorId()
      Returns:
      the cursor ID, or null if not set
    • setCursorId

      public void setCursorId(@Nullable Long cursorId)
      Parameters:
      cursorId - the cursor ID
    • getTransactionNumber

      @Nullable public Long getTransactionNumber()
      Returns:
      the transaction number, or null if not set
    • setTransactionNumber

      public void setTransactionNumber(@Nullable Long transactionNumber)
      Parameters:
      transactionNumber - the transaction number
    • getSessionId

      @Nullable public String getSessionId()
      Returns:
      the logical session ID, or null if not set
    • setSessionId

      public void setSessionId(@Nullable String sessionId)
      Parameters:
      sessionId - the logical session ID
    • isUnixSocket

      public boolean isUnixSocket()
      Returns:
      true if the connection uses a Unix domain socket
    • setUnixSocket

      public void setUnixSocket(boolean unixSocket)
      Parameters:
      unixSocket - whether the connection uses a Unix domain socket
    • getQueryText

      @Nullable public String getQueryText()
      Returns:
      the query text, or null if not set
    • setQueryText

      public void setQueryText(@Nullable String queryText)
      Parameters:
      queryText - the query text
    • getResponseStatusCode

      @Nullable public String getResponseStatusCode()
      Returns:
      the response status code, or null if not set
    • setResponseStatusCode

      public void setResponseStatusCode(@Nullable String responseStatusCode)
      Parameters:
      responseStatusCode - the response status code