mongo

package
v0.0.0-...-7ebff8f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0, BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

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.

Example
package main

import (
	"context"

	mongotrace "github.com/DataDog/dd-trace-go/v2/contrib/go.mongodb.org/mongo-driver/mongo"

	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
	// connect to MongoDB
	opts := options.Client()
	opts.Monitor = mongotrace.NewMonitor()
	opts.ApplyURI("mongodb://localhost:27017")
	client, err := mongo.Connect(context.Background(), opts)
	if err != nil {
		panic(err)
	}
	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"},
		}},
	})
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMonitor

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

NewMonitor creates a new mongodb event CommandMonitor.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option describes options for the Mongo integration.

type OptionFn

type OptionFn func(*config)

OptionFn represents options applicable to NewMonitor.

func WithAnalytics

func WithAnalytics(on bool) OptionFn

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) OptionFn

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

func WithService

func WithService(name string) OptionFn

WithService 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL