customapm

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package customapm provides types and methods to deal APM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TXFromCtx

func TXFromCtx(ctx context.Context, txName string, txType string) *apm.Transaction

TXFromCtx Creates a new TX if none is found in the context, otherwise reuses the existing one.

Note on TX and Span naming:

The name and type of a transaction and span depend on the specific operation being performed by the request. Here's an example of how you might name and type a transaction and span for an incoming request to insert data into a db:

Transaction:

- Name: "post-user" - Type: "request.post.user"

Span:

- Name: "insert-user" - Type: "db.sql.insert"

In this example, the tx was named "post-user" to describe the operation being performed "request.post.user".

For the span, it was named "insert-user" to describe a specific operation being performed by the span. It was also categorized as "db.sql.insert", which indicates that it involves a database operation.

If the span type contains two dots, they are assumed to separate the type and subtype parts of the span type. The action will not be set in this case.

For example, if you use a span type of "db.sql.insert", this indicates that the span represents a database operation of type "db", subtype "sql", and action "insert". The StartSpan() method will automatically parse the span type string and set the appropriate values for the Type, Subtype, and Action fields of the SpanData object.

If you use a span type of "db.sql", this indicates that the span represents a database operation of type "db" and subtype "sql". The Action field of the SpanData object will be left blank in this case.

If you use a span type of "db", this indicates that the span represents a generic database operation of type "db". Both the Subtype and Action fields of the SpanData object will be left blank in this case.

func Trace

func Trace(
	ctx context.Context,
	what, nameOf string,
	operation status.Status,
	l sypl.ISypl,
	metric *expvar.Int,
) (context.Context, *apm.Span)

Trace will trace an operation. It uses the existing TX otherwise it fallback creating a new TX then it creates a new span within the TX.

NOTE: It's up to the developer to call `span.End()`.

Note on TX and Span naming:

The name and type of a transaction and span depend on the specific operation being performed by the request. Here's an example of how you might name and type a transaction and span for an incoming request to insert data into a db:

Transaction:

- Name: "post-user" - Type: "request.post.user"

Span:

- Name: "insert-user" - Type: "db.sql.insert"

In this example, the tx was named "post-user" to describe the operation being performed "request.post.user".

For the span, it was named "insert-user" to describe a specific operation being performed by the span. It was also categorized as "db.sql.insert", which indicates that it involves a database operation.

If the span type contains two dots, they are assumed to separate the type and subtype parts of the span type. The action will not be set in this case.

For example, if you use a span type of "db.sql.insert", this indicates that the span represents a database operation of type "db", subtype "sql", and action "insert". The StartSpan() method will automatically parse the span type string and set the appropriate values for the Type, Subtype, and Action fields of the SpanData object.

If you use a span type of "db.sql", this indicates that the span represents a database operation of type "db" and subtype "sql". The Action field of the SpanData object will be left blank in this case.

If you use a span type of "db", this indicates that the span represents a generic database operation of type "db". Both the Subtype and Action fields of the SpanData object will be left blank in this case.

func TraceError

func TraceError(
	ctx context.Context,
	err error,
	l sypl.ISypl,
	metric *expvar.Int,
) error

TraceError is a helper function to trace an error. It will log the error with the APM fields, and tell APM that it was an error. It will also set the span outcome to failure.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger satisfies `apm.Logger` interface.

func NewLogger

func NewLogger() (*Logger, error)

NewLogger returns a new APM logger.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf implements required `Debugf` interface.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf implements required `Errorf` interface.

type Outcome

type Outcome string

Outcome is the outcome of a span. It can be either success or failure.

const (
	// Failure is the outcome when the span failed.
	Failure Outcome = "failure"

	// Success is the outcome when the span succeeded.
	Success Outcome = "success"
)

func (Outcome) String

func (o Outcome) String() string

Jump to

Keyboard shortcuts

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