logbrewasynq

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 10 Imported by: 0

README

LogBrew Asynq integration

This module adds producer-to-worker trace propagation, queue spans for every attempt, and one correlated issue for terminal failures or panics. It never copies task payloads, headers, or error messages into telemetry.

go get github.com/LogBrewCo/sdk/go/logbrew/asynq@latest

Enqueue through the integration so it can construct the task with the producer span's W3C traceparent header. Pass normal Asynq options after the config.

info, err := logbrewasynq.EnqueueContext(ctx, asynqClient, "receipt:email", payload,
  logbrewasynq.EnqueueConfig{
    Client: logbrewClient,
    Queue:  "mailers",
  },
  asynq.MaxRetry(5),
)

Install the middleware before application middleware that should observe the active LogBrew trace:

instrumentation, err := logbrewasynq.NewMiddleware(logbrewasynq.Config{
  Client: logbrewClient,
})
if err != nil {
  return err
}
mux.Use(instrumentation)

Retryable returned errors remain error spans without creating an issue on every attempt. The last returned error, asynq.SkipRetry, and asynq.RevokeTask create a terminal issue. Each unhandled panic creates an issue before Asynq recovers it for its retry policy. Issues include exception type, bounded capture frames, attempt counts when Asynq provides them, queue/task names, and exact trace/span context. Set DisableIssues when the application owns issue capture. Custom span metadata passes through the core operation metadata filter.

The application still owns Redis, the Asynq client and server lifecycle, retries, shutdown, and LogBrew flushing.

Documentation

Overview

Package logbrewasynq correlates Asynq producers and workers with LogBrew queue spans and privacy-bounded job issues.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnqueueContext

func EnqueueContext(
	ctx context.Context,
	enqueuer Enqueuer,
	taskType string,
	payload []byte,
	config EnqueueConfig,
	options ...asynq.Option,
) (*asynq.TaskInfo, error)

EnqueueContext constructs and enqueues one task inside a producer span. The generated traceparent replaces case variants in app-owned task headers; payloads and headers are never copied into telemetry.

func NewMiddleware

func NewMiddleware(config Config) (asynq.MiddlewareFunc, error)

NewMiddleware returns Asynq middleware that continues producer traces, records each processing attempt, and captures terminal returned errors plus every unhandled panic.

Types

type Config

type Config struct {
	Client        *logbrew.Client
	DisableIssues bool
	EventIDPrefix string
	Metadata      map[string]any
	SpanIDFactory func() string
	Now           func() time.Time
	OnError       func(error)
}

Config controls worker middleware. Terminal returned errors and unhandled panics create issues by default; DisableIssues leaves them as spans only.

type EnqueueConfig

type EnqueueConfig struct {
	Client        *logbrew.Client
	Queue         string
	Headers       map[string]string
	EventIDPrefix string
	Metadata      map[string]any
	SpanIDFactory func() string
	Now           func() time.Time
	OnError       func(error)
}

EnqueueConfig controls producer telemetry and task propagation.

type Enqueuer

type Enqueuer interface {
	EnqueueContext(context.Context, *asynq.Task, ...asynq.Option) (*asynq.TaskInfo, error)
}

Enqueuer is implemented by *asynq.Client.

Jump to

Keyboard shortcuts

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