dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/go.mongodb.org/mongo-driver/mongo Index | Examples | Files

package mongo

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/go.mongodb.org/mongo-driver/mongo"

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

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


// connect to MongoDB
opts := options.Client()
opts.Monitor = mongotrace.NewMonitor()
client, err := mongo.Connect(context.Background(), opts)
if err != nil {
db := client.Database("example")
inventory := db.Collection("inventory")

inventory.InsertOne(context.Background(), bson.D{
    {Key: "item", Value: "canvas"},
    {Key: "qty", Value: 100},
    {Key: "tags", Value: bson.A{"cotton"}},
    {Key: "size", Value: bson.D{
        {Key: "h", Value: 28},
        {Key: "w", Value: 35.5},
        {Key: "uom", Value: "cm"},



Package Files

mongo.go option.go

func NewMonitor Uses

func NewMonitor(opts ...Option) *event.CommandMonitor

NewMonitor creates a new mongodb event CommandMonitor.

type Option Uses

type Option func(*config)

Option represents an option that can be passed to Dial.

func WithAnalytics Uses

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) Option

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName Uses

func WithServiceName(name string) Option

WithServiceName sets the given service name for the dialled connection. When the service name is not explicitly set it will be inferred based on the request to AWS.

Package mongo imports 11 packages (graph). Updated 2020-08-04. Refresh now. Tools for package owners.