ppgocql

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

ppgocql

This package instruments the gocql package.

Installation

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

Usage

PkgGoDev

This package instruments all queries created from gocql session. Use the NewObserver as the gocql.QueryObserver or gocql.BatchObserver:

cluster := gocql.NewCluster("127.0.0.1")

observer := ppgocql.NewObserver()
cluster.QueryObserver = observer
cluster.BatchObserver = observer

It is necessary to pass the context containing the pinpoint.Tracer using the pinpoint.WithContext function.

import (
    "github.com/gocql/gocql"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/gocql"
)

func doCassandra(w http.ResponseWriter, r *http.Request) {
    observer := ppgocql.NewObserver()
    cluster := gocql.NewCluster("127.0.0.1")
    cluster.QueryObserver = observer
    cluster.BatchObserver = observer

    session, _ := cluster.CreateSession()
    query := session.Query(`SELECT id, text FROM tweet WHERE timeline = ? LIMIT 1`, "me")
    err := query.WithContext(r.Context()).Consistency(gocql.One).Scan(&id, &text)
    ...
}

Full Example Source

Documentation

Overview

Package ppgocql instruments the gocql package (https://github.com/gocql/gocql).

This package instruments all queries created from gocql session. Use the NewObserver as the gocql.QueryObserver or gocql.BatchObserver:

cluster := gocql.NewCluster("127.0.0.1")
cluster.QueryObserver = ppgocql.NewObserver()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Observer

type Observer struct{}

func NewObserver

func NewObserver() *Observer

NewObserver returns a query or batch observer ready to instrument.

func (*Observer) ObserveBatch

func (o *Observer) ObserveBatch(ctx context.Context, batch gocql.ObservedBatch)

ObserveBatch instruments all batch queries created from gocql session. It is necessary to pass the context containing the pinpoint.Tracer to the query. Refer an example of ObserveQuery.

func (*Observer) ObserveQuery

func (o *Observer) ObserveQuery(ctx context.Context, query gocql.ObservedQuery)

ObserveQuery instruments all queries created from gocql session. It is necessary to pass the context containing the pinpoint.Tracer to the query.

query := session.Query(query)
ctx := pinpoint.NewContext(context.Background(), tracer)
query.WithContext(ctx).Consistency(gocql.One).Scan(&id, &text)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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