Documentation

Overview

    Package mongo-driver provides functions to trace the [go.mongodb.org/mongo-driver/mongo](https://github.com/mongodb/mongo-go-driver) package. It support v0.2.0 of github.com/mongodb/mongo-go-driver

    `NewMonitor` will return an event.CommandMonitor which is used to trace requests.

    This code was originally based on the following: - https://github.com/DataDog/dd-trace-go/tree/02f0449efa3cb382d499fadc873957385dcb2192/contrib/go.mongodb.org/mongo-driver/mongo - https://github.com/DataDog/dd-trace-go/tree/v1.23.3/ddtrace/ext

    Example
    Output:
    
    

    Index

    Examples

    Constants

    View Source
    const (
    	DBApplicationKey = kv.Key("db.application")
    	DBNameKey        = kv.Key("db.name")
    	DBTypeKey        = kv.Key("db.type")
    	DBInstanceKey    = kv.Key("db.instance")
    	DBUserKey        = kv.Key("db.user")
    	DBStatementKey   = kv.Key("db.statement")
    )
    View Source
    const (
    	// PeerHostname records the host name of the peer.
    	PeerHostnameKey = kv.Key("peer.hostname")
    	// PeerPort records the port number of the peer.
    	PeerPortKey = kv.Key("peer.port")
    )
    View Source
    const (
    	TargetHostKey   = kv.Key("out.host")
    	TargetPortKey   = kv.Key("out.port")
    	HTTPMethodKey   = kv.Key("http.method")
    	HTTPCodeKey     = kv.Key("http.code")
    	HTTPURLKey      = kv.Key("http.url")
    	SpanTypeKey     = kv.Key("span.type")
    	ServiceNameKey  = kv.Key("service.name")
    	ResourceNameKey = kv.Key("resource.name")
    	ErrorKey        = kv.Key("error")
    	ErrorMsgKey     = kv.Key("error.msg")
    )

    Variables

    This section is empty.

    Functions

    func DBApplication

    func DBApplication(dbApplication string) kv.KeyValue

      DBApplication indicates the application using the database.

      func DBInstance

      func DBInstance(dbInstance string) kv.KeyValue

        DBInstance indicates the instance name of Database.

        func DBName

        func DBName(dbName string) kv.KeyValue

          DBName indicates the database name.

          func DBStatement

          func DBStatement(dbStatement string) kv.KeyValue

            DBStatement records a database statement for the given database type.

            func DBType

            func DBType(dbType string) kv.KeyValue

              DBType indicates the type of Database.

              func DBUser

              func DBUser(dbUser string) kv.KeyValue

                DBUser indicates the user name of Database, e.g. "readonly_user" or "reporting_user".

                func Error

                func Error(err bool) kv.KeyValue

                  Error specifies whether an error occurred.

                  func ErrorMsg

                  func ErrorMsg(errorMsg string) kv.KeyValue

                    ErrorMsg specifies the error message.

                    func HTTPCode

                    func HTTPCode(httpCode string) kv.KeyValue

                      HTTPCode sets the HTTP status code as a attribute.

                      func HTTPMethod

                      func HTTPMethod(httpMethod string) kv.KeyValue

                        HTTPMethod specifies the HTTP method used in a span.

                        func HTTPURL

                        func HTTPURL(httpURL string) kv.KeyValue

                          HTTPURL sets the HTTP URL for a span.

                          func NewMonitor

                          func NewMonitor(serviceName string, opts ...Option) *event.CommandMonitor

                            NewMonitor creates a new mongodb event CommandMonitor.

                            func PeerHostname

                            func PeerHostname(peerHostname string) kv.KeyValue

                              PeerHostname records the host name of the peer.

                              func PeerPort

                              func PeerPort(peerport string) kv.KeyValue

                                PeerPort records the port number of the peer.

                                func ResourceName

                                func ResourceName(resourceName string) kv.KeyValue

                                  ResourceName defines the Resource name for the Span.

                                  func ServiceName

                                  func ServiceName(serviceName string) kv.KeyValue

                                    ServiceName defines the Service name for this Span.

                                    func SpanType

                                    func SpanType(spanType string) kv.KeyValue

                                      SpanType defines the Span type (web, db, cache).

                                      func TargetHost

                                      func TargetHost(targetHost string) kv.KeyValue

                                        TargetHost sets the target host address.

                                        func TargetPort

                                        func TargetPort(targetPort string) kv.KeyValue

                                          TargetPort sets the target host port.

                                          Types

                                          type Config

                                          type Config struct {
                                          	Tracer trace.Tracer
                                          }

                                            Config is used to configure the mongo tracer.

                                            type Option

                                            type Option func(*Config)

                                              Option specifies instrumentation configuration options.

                                              func WithTracer

                                              func WithTracer(tracer trace.Tracer) Option

                                                WithTracer specifies a tracer to use for creating spans. If none is specified, a tracer named "go.opentelemetry.io/contrib/plugins/go.mongodb.org/mongo-driver" from the global provider is used.