datalog

package
v0.0.2 Latest Latest
Warning

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

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

README

服务端数据埋点 SDK

提供日志打点 + kafka + 神策 多通道能力

1. 准备工作

  • 安装 gokit

go get -u github.com/LabKiko/kiko-gokit

2. 使用示例

// 初始化数据打点配置项
datalog, err = Dial("infra.bff.feeds",
    WithBasePath("../data"),
)
if err != nil {
    panic(err)
}

defer datalog.Close()

attributes := make([]attribute.KeyValue, 0)
attributes = append(attributes,
    attribute.String("biz_system", "sona"),
    attribute.String("platform_type", "server"),
)

err := datalog.Write(context.Background(), &Event{
    Name:         "addpersonal",
    DistinctId:   "10000",
    DistinctType: User,
    Time:         time.Now(),
}, attributes...)
  • ctx 上下文,用于 链路追踪 获取 trace 信息
  • event 信息,kafka topic 会自动加上初始化传递的 app_id,组合最终显示为 ${app_id}-${event}, kafka topic 规范请参考
  • attributes 键值

3. 其他注意事项

神策保留字段

为了保证查询时属性名不与系统变量名冲突,设置如下保留字段,请避免其作为事件名和属性名(properties 中的 key)使用:

date
datetime
distinct_id
event
events
event_id
first_id
id
original_id
device_id
properties
second_id
time
user_id
users
user_group 开头
user_tag 开头

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopy

func DeepCopy(value map[string]interface{}) map[string]interface{}

Types

type DataLog

type DataLog interface {
	Write(ctx context.Context, event *Event, attributes ...attribute.KeyValue) error
	Flush() error
	Close() error
}

func Dial

func Dial(appId string, options ...Option) (DataLog, error)

type DistinctType

type DistinctType int8
const (
	Guest DistinctType = iota // 访客
	User                      // 用户
)

func (DistinctType) IsGuest

func (d DistinctType) IsGuest() bool

IsGuest 是否游客

func (DistinctType) IsUser

func (d DistinctType) IsUser() bool

IsUser 是否用户

type Event

type Event struct {
	Name         string       // 事件名称
	DistinctId   string       // 唯一标识 ID; 用户UID, 或者游客ID
	DistinctType DistinctType // 唯一标识类型:(0-访客,1-用户)
	Time         time.Time    // 事件时间
}

type Exporter

type Exporter interface {
	Write(ctx context.Context, event *Event, metadata Metadata) error
	Flush() error
	Close() error
}

Exporter 导出器

type Filter

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

Filter is a logger filter.

func NewFilter

func NewFilter(exporter Exporter, opts ...FilterOption) *Filter

NewFilter new a logger filter.

func (*Filter) Close

func (f *Filter) Close() error

func (*Filter) Flush

func (f *Filter) Flush() error

func (*Filter) Write

func (f *Filter) Write(ctx context.Context, event *Event, metadata Metadata) error

type FilterOption

type FilterOption func(*Filter)

FilterOption is filter option.

func FilterFunc

func FilterFunc(f func(ctx context.Context, event *Event, metadata Metadata) bool) FilterOption

FilterFunc with filter func.

func FilterKey

func FilterKey(key ...string) FilterOption

FilterKey with filter key.

func FilterValue

func FilterValue(value ...string) FilterOption

FilterValue with filter value.

type Kafka

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

func NewKafka

func NewKafka(opts *config) (*Kafka, error)

func (*Kafka) Close

func (w *Kafka) Close() error

func (*Kafka) Flush

func (w *Kafka) Flush() error

func (*Kafka) Write

func (w *Kafka) Write(ctx context.Context, event *Event, metadata Metadata) error

type Logger

type Logger struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(opts *config) (*Logger, error)

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Flush

func (l *Logger) Flush() error

func (*Logger) Write

func (l *Logger) Write(ctx context.Context, event *Event, metadata Metadata) error

type Metadata

type Metadata map[string]interface{}

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithAppId

func WithAppId(appId string) Option

func WithBasePath

func WithBasePath(path string) Option

WithBasePath set base path.

func WithBatch

func WithBatch(batch bool) Option

func WithBatchBulkSizeMax

func WithBatchBulkSizeMax(size int) Option

func WithBrokers

func WithBrokers(brokers []string) Option

func WithDebug

func WithDebug(debug bool) Option

func WithEncoderConfig

func WithEncoderConfig(encoderConfig zapcore.EncoderConfig) Option

WithEncoderConfig set logger encoderConfig

func WithLogDisable

func WithLogDisable(disable bool) Option

WithLogDisable disable logger

func WithMetadata

func WithMetadata(md map[string]string) Option

WithMetadata set default fields for the logger

func WithProjectName

func WithProjectName(projectName string) Option

func WithServiceName

func WithServiceName(serviceName string) Option

func WithTimeout

func WithTimeout(timeout int) Option

func WithToken

func WithToken(token string) Option

type OptionFunc

type OptionFunc func(*config)

type SensorsData

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

func NewSensorsData

func NewSensorsData(opts *config) *SensorsData

func (*SensorsData) Close

func (s *SensorsData) Close() error

Close 安全关闭

func (*SensorsData) Flush

func (s *SensorsData) Flush() error

Flush 将内存数据写入

func (*SensorsData) Write

func (s *SensorsData) Write(ctx context.Context, event *Event, metadata Metadata) error

Directories

Path Synopsis
Package attribute provides key and value attributes.
Package attribute provides key and value attributes.

Jump to

Keyboard shortcuts

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