kinesiswriter

package module
v0.0.0-...-6fba0ff Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 15 Imported by: 0

README

go-kinesis-writer

GoDoc

go-kinesis-writer is a library for Go that allows output from the uber-go/zap to be sent to Amazon Kinesis Data Streams. By using this library, logs generated by zap can be streamed to Amazon Kinesis Data Streams in real-time, enabling the analysis and processing of large-scale log data.

Features

  • Easy Configuration: Add a few lines to your existing zap configuration to start outputting logs to Kinesis Data Streams.
  • Asynchronous Transmission: Logs are sent asynchronously, ensuring that your application's performance is not hindered.
  • Batch Processing: Logs are batch processed before being transmitted to Kinesis for efficient transport.

Prerequisites

  • Go 1.x
  • An AWS account and configured Amazon Kinesis stream

Installation

go get github.com/mackee/go-kinesis-writer

Usage

Basic Setup

This example is use uber-go/zap as the logger. First, set up your zap logger. Then, use go-kinesis-writer to redirect zap's output to Kinesis.

package main

import (
    "github.com/mackee/go-kinesis-writer"
    "go.uber.org/zap"
)

func main() {
    // Setting up zap logger
    logger, _ := zap.NewProduction()

    ctx := context.Background()
    // Configuring Kinesis Writer
    kw, err := kinesiswriter.New(ctx, "your-kinesis-stream-arn")
    if err != nil {
        logger.Fatal("Failed to create kinesis writer", zap.Error(err))
    }

    // Integrating Kinesis Writer with zap
    logger = logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
        return zapcore.NewCore(
            zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
            kw,
            zapcore.DebugLevel,
        )
    }))

    // Logging a test message
    logger.Info("This is a test log sent to Amazon Kinesis")
}

Contributing

If you are interested in contributing to go-kinesis-writer, please feel free to submit pull requests or issues. Before contributing, please read the contribution guidelines.

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KinesisClient

type KinesisClient interface {
	PutRecords(ctx context.Context, params *kinesis.PutRecordsInput, optFns ...func(*kinesis.Options)) (*kinesis.PutRecordsOutput, error)
}

type Writer

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

Writer writes records to a Kinesis stream.

func New

func New(ctx context.Context, streamARN string, opts ...WriterConfigOption) (*Writer, error)

New creates a new Writer.

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Sync

func (w *Writer) Sync() error

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

type WriterConfigOption

type WriterConfigOption func(*writerConfig)

WriterConfigOption is a configuration option for a Writer.

func WithBufferErrorHandler

func WithBufferErrorHandler(handler func(err error, elements [][]byte)) WriterConfigOption

WithBufferErrorHandler sets the error handler for the buffer.

func WithBufferFlushInterval

func WithBufferFlushInterval(interval time.Duration) WriterConfigOption

WithBufferFlushInterval sets the flush interval for the buffer.

func WithBufferFlushTimeout

func WithBufferFlushTimeout(timeout time.Duration) WriterConfigOption

WithBufferFlushTimeout sets the flush timeout for the buffer.

func WithBufferRecordWindow

func WithBufferRecordWindow(window uint32) WriterConfigOption

WithBufferRecordWindow sets the record window for the buffer.

func WithBufferWriteTimeout

func WithBufferWriteTimeout(timeout time.Duration) WriterConfigOption

WithBufferWriteTimeout sets the write timeout for the buffer.

func WithKinesisClient

func WithKinesisClient(client KinesisClient) WriterConfigOption

WithKinesisClient sets the Kinesis client.

func WithSplitFunc

func WithSplitFunc(fn bufio.SplitFunc) WriterConfigOption

WithSeparator sets the separator between records.

Jump to

Keyboard shortcuts

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