zapai

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// SinkScheme is the registerable Sink Scheme for appinsights.
	SinkScheme = "appinsights"
)

Variables

View Source
var ApplicationContextMappers = map[string]string{
	"version": "ai.application.ver",
}

ApplicationContextMappers are the default ApplicationContext tag mappers.

View Source
var CloudContextMappers = map[string]string{
	"az_role":          "ai.cloud.role",
	"az_role_instance": "ai.cloud.roleInstance",
}

CloudContextMappers are the default CloudContext tag mappers.

View Source
var DefaultMappers = func() map[string]string {
	m := map[string]string{}
	for _, mm := range allMappers {
		for k, v := range mm {
			m[k] = v
		}
	}
	return m
}()

DefaultMappers is a convenience var which is a combined tagMapper of all hardcoded mappers.

View Source
var DeviceContextMappers = map[string]string{
	"device_id":   "ai.device.id",
	"locale":      "ai.device.locale",
	"model":       "ai.device.model",
	"oem":         "ai.device.oemName",
	"os_version":  "ai.device.osVersion",
	"device_type": "ai.device.type",
}

DeviceContextMappers are the default DeviceContext tag mappers.

View Source
var InternalContextMappers = map[string]string{
	"ai_sdk_version":   "ai.internal.sdkVersion",
	"ai_agent_version": "ai.internal.agentVersion",
	"node_name":        "ai.internal.nodeName",
}

InternalContextMappers are the default InternalContext tag mappers.

View Source
var LocationContextMappers = map[string]string{
	"ip": "ai.location.ip",
}

LocationContextMappers are the default LocationContext tag mappers.

View Source
var OperationContextMappers = map[string]string{
	"operation_id":     "ai.operation.id",
	"operation_name":   "ai.operation.name",
	"parent_id":        "ai.operation.parentId",
	"synthetic_source": "ai.operation.syntheticSource",
	"correlation_id":   "ai.operation.correlationVector",
}

OperationContextMappers are the default OperationContext tag mappers.

View Source
var SessionContextMappers = map[string]string{
	"session_id":       "ai.session.id",
	"session_is_first": "ai.session.isFirst",
}

SessionContextMappers are the default SessionContext tag mappers.

View Source
var UserContextMappers = map[string]string{
	"account":           "ai.user.accountId",
	"anonymous_user_id": "ai.user.id",
	"user_id":           "ai.user.authUserId",
}

UserContextMappers are the default UserContext tag mappers.

Functions

This section is empty.

Types

type Core

type Core struct {
	zapcore.LevelEnabler
	// contains filtered or unexported fields
}

Core implements zapcore.Core for appinsights. Core only knows how to write to, and should only be used with, a corresponding appinsights Sink.

Internally, the Core implements Write(zapcore.Entry, []zapcore.Field) by building an appinsights.TraceTelemetry out of the zap inputs, then serializing it to a []byte using a shared common gob.Encoder, and passes that to the Sink.Write([]byte) (which knows how to decode it back in to a TraceTelemetry).

func NewCore

func NewCore(le zapcore.LevelEnabler, out zapcore.WriteSyncer) *Core

NewCore creates a new appinsights zap core. Should only be initialized using an appinsights Sink as the zapcore.WriteSyncer argument - other sinks will not error but will also not produce meaningful output.

func (*Core) Check

func (c *Core) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry

Check implements zapcore.Core

func (*Core) Sync

func (c *Core) Sync() error

func (*Core) With

func (c *Core) With(fields []zapcore.Field) zapcore.Core

func (*Core) WithFieldMappers

func (c *Core) WithFieldMappers(fieldMappers ...map[string]string) *Core

func (*Core) Write

func (c *Core) Write(entry zapcore.Entry, fields []zapcore.Field) error

Write implements zapcore.Core

type Sink

type Sink struct {
	*SinkConfig
	// contains filtered or unexported fields
}

Sink implements zap.Sink for appinsights. Sink is not inherently safe for concurrent use - the zap constructors will wrap it for concurrency.

To conform to the zap.Sink interface, Sink implements Write([]byte), where it expects that the passed []byte is an encoded gob that can be decoded in to a valid appinsights.TraceTelemetry. Passing any other []byte input is an error.

func (*Sink) Close

func (s *Sink) Close() error

Close flushes and tears down the appinsights channel. Waits up to the GracePeriod duration for sends and retries to complete.

func (*Sink) Sync

func (s *Sink) Sync() error

Sync flushes the current channel queue.

func (*Sink) Write

func (s *Sink) Write(b []byte) (int, error)

Write accepts a gob []byte that must be Decodable to an appinsights.TraceTelemetry{}, which is then sent to appinsights via the telemetryTracker.

type SinkConfig

type SinkConfig struct {
	GracePeriod time.Duration
	appinsights.TelemetryConfiguration
}

SinkConfig is a container struct for an appinsights Sink configuration.

func (*SinkConfig) URI

func (sc *SinkConfig) URI() string

URI builds an appinsights Sink URI string suitable for passing to zap.Open.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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