call

package
v1.71.1 Latest Latest
Warning

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

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

Documentation

Overview

Package call helps support tracking latency and other metrics for calls.

Copyright 2022 Outreach Corporation. All Rights Reserved. Description: This file contains the call option definition used by trace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	// Name is the name of the call, this is used for the message of the log
	// and the name of the trace.
	Name string

	// Type is the type of the call, see `Type` for more information.
	Type Type

	// Opts are the options for this call, see `Options` for more information.
	Opts Options

	// Kind is the type of call being made. See metrics.CallKind for more
	// information.
	Kind metrics.CallKind

	// Args are the arguments to the call, this is used for attributes on
	// logs and traces.
	Args []logf.Marshaler

	// ErrInfo is the information for an error that occurred during the call.
	// This is set by SetStatus and used for reporting that an error occurred.
	ErrInfo *events.ErrorInfo

	events.Times
	events.Durations
	// contains filtered or unexported fields
}

Info tracks information about an ongoing synchronous call.

func (*Info) AddArgs

func (info *Info) AddArgs(ctx context.Context, args ...logf.Marshaler)

AddArgs appends the provided logf.Marshalers to the Args slice.

func (*Info) ApplyOpts added in v1.31.0

func (info *Info) ApplyOpts(ctx context.Context, args ...logf.Marshaler)

ApplyOpts applies call Option functions to the call Info object. even if args are logf.Marshalers, but there might be some call.Options this is done intentionally to preserve compatibility of StartCall API and extend it with new functionality

func (*Info) End

func (info *Info) End(ctx context.Context)

End records the finished time and updates durations.

func (*Info) MarshalLog

func (info *Info) MarshalLog(addField func(key string, value interface{}))

MarshalLog addes log.Marshaler support, logging most of the fields.

func (*Info) ReportLatency

func (info *Info) ReportLatency(ctx context.Context)

ReportLatency reports the call latency via the metrics package based on the call Kind. If the Kind is not one of HTTP, GRPC or Outbound, it does nothing.

func (*Info) SetStatus

func (info *Info) SetStatus(ctx context.Context, err error)

SetStatus updates the ErrInfo field based on the error.

func (*Info) Start

func (info *Info) Start(ctx context.Context, name string)

Start initializes info with the start time and some name.

type Option added in v1.31.0

type Option func(c *Info)

Option defines the call Info adjustment function

func (Option) MarshalLog added in v1.31.0

func (Option) MarshalLog(addField func(string, interface{}))

MarshalLog is defined for being compliant with trace.StartCall contract

type Options added in v1.70.0

type Options struct {
	// DisableInfoLogging turns off per-call info logging if set to true. If false, every successful
	// (statuscodes.CategoryOK) call will have an Info line emitted.
	DisableInfoLogging bool
}

Options contains options for all tracing calls.

type Tracker

type Tracker struct{}

Tracker helps manage a call info via the context.

func (*Tracker) EndCall

func (t *Tracker) EndCall(ctx context.Context)

EndCall is meant to be called in a defer abc.EndCall(ctx) pattern. It checks if there is a panic. If so, it uses that to update the current call Info object. It calls info.End(ctx) before returning. It rethrows any panic.

func (*Tracker) Info

func (t *Tracker) Info(ctx context.Context) *Info

Info returns the call Info object stashed in the context. If there is no call Info object, it returns nil. Be sure to check for nil before using the returned value.

func (*Tracker) StartCall

func (t *Tracker) StartCall(ctx context.Context, name string, args []logf.Marshaler) context.Context

StartCall creates a new call Info object and returns a new context where tracker.Info(ctx) will return the newly setup call Info object.

type Type

type Type string

Type tracks the type of call being made.

const (
	// TypeHTTP is a constant that denotes the call type being an HTTP
	// request.
	TypeHTTP Type = "http"

	// TypeGRPC is a constant that denotes the call type being a gRPC
	// request.
	TypeGRPC Type = "grpc"

	// TypeOutbound is a constant that denotes the call type being an
	// outbound request.
	TypeOutbound Type = "outbound"
)

Contains the call type constants.

Jump to

Keyboard shortcuts

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