ppmongo

package module
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

README

ppmongo

This package instruments the mongodb/mongo-go-driver package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/mongodriver
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/mongodriver"

Usage

PkgGoDev

This package instruments the mongo-go-driver calls. Use the NewMonitor as Monitor field of mongo-go-driver's ClientOptions.

opts := options.Client()
opts.Monitor = ppmongo.NewMonitor()
client, err := mongo.Connect(ctx, opts)

It is necessary to pass the context containing the pinpoint.Tracer to mongo.Client.

collection := client.Database("testdb").Collection("example")
ctx := pinpoint.NewContext(context.Background(), tracer)
collection.InsertOne(ctx, bson.M{"foo": "bar", "apm": "pinpoint"})
import (
    "go.mongodb.org/mongo-driver/bson"
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/mongodriver"
)

func mongodb(w http.ResponseWriter, r *http.Request) {
    opts := options.Client()
    opts.ApplyURI("mongodb://localhost:27017")
    opts.Monitor = ppmongo.NewMonitor()
    client, err := mongo.Connect(context.Background(), opts)

    collection := client.Database("testdb").Collection("example")
    _, err = collection.InsertOne(r.Context(), bson.M{"foo": "bar", "apm": "pinpoint"})
    ...
}

Full Example Source

Documentation

Overview

Package ppmongo instruments the mongodb/mongo-go-driver package (https://github.com/mongodb/mongo-go-driver).

This package instruments the mongo-go-driver calls. Use the NewMonitor as Monitor field of mongo-go-driver's ClientOptions.

opts := options.Client()
opts.Monitor = ppmongo.NewMonitor()
client, err := mongo.Connect(ctx, opts)

It is necessary to pass the context containing the pinpoint.Tracer to mongo.Client.

collection := client.Database("testdb").Collection("example")
ctx := pinpoint.NewContext(context.Background(), tracer)
collection.InsertOne(ctx, bson.M{"foo": "bar", "apm": "pinpoint"})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMonitor

func NewMonitor() *event.CommandMonitor

NewMonitor returns a *event.CommandMonitor ready to instrument.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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