mongo

package module
v0.0.0-...-1db7dc6 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

Go2Sky with Mongo

Installation

go get -u github.com/SkyAPM/go2sky-plugins/mongo

Usage

import (
	"github.com/SkyAPM/go2sky"
	"github.com/SkyAPM/go2sky/reporter"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	
	mongoPlugin "go2sky-plugins/mongo"
)

// init reporter
re, err := reporter.NewLogReporter()
defer re.Close()

// init tracer
tracer, err := go2sky.NewTracer("service-name", go2sky.WithReporter(re))
if err != nil {
    log.Fatalf("init tracer error: %v", err)
}

// init connect mongodb.
client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(dsn).SetMonitor(mongoPlugin.Middleware(tracer)))
if err != nil {
    log.Fatalf("connect mongodb error %v \n", err)
}

...

Documentation

Index

Constants

View Source
const (
	// ComponentMongo ComponentID.
	ComponentMongo int32 = 42

	// ComponentMongoDB db.type.
	ComponentMongoDB string = "MongoDB"
)

Variables

This section is empty.

Functions

func GetMongoDBStatement

func GetMongoDBStatement(evt *event.CommandStartedEvent) string

GetMongoDBStatement get statement.

func GetOpName

func GetOpName(operation string) string

GetOpName get operation name.

func Middleware

func Middleware(tracer *go2sky.Tracer, peer string, opts ...Option) *event.CommandMonitor

Middleware mongo monitor.

Types

type Option

type Option func(span go2sky.Span, evt *event.CommandStartedEvent)

Option custom option.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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