<commit_before>package rollbarhandler

import (
	"github.com/goph/emperror"
	"github.com/goph/emperror/httperr"
	"github.com/goph/emperror/internal/keyvals"
	"github.com/rollbar/rollbar-go"
)

type Handler struct {
	client *rollbar.Client
}

func New(token, environment, codeVersion, serverHost, serverRoot string) *Handler {
	return NewFromClient(rollbar.New(token, environment, codeVersion, serverHost, serverRoot))
}

func NewFromClient(client *rollbar.Client) *Handler {
	return &Handler{
		client: client,
	}
}

func (h *Handler) Handle(err error) {
	// Get HTTP request (if any)
	req, httpok := httperr.HTTPRequest(err)

	ctx := keyvals.ToMap(emperror.Context(err))

	// Expose the stackTracer interface on the outer error (if there is stack trace in the error)
	err = emperror.ExposeStackTrace(err)

	// Convert error with stack trace to an internal error type
	if e, ok := err.(stackTracer); ok {
		err = newCauseStacker(e)
	}

	if httpok {
		h.client.RequestErrorWithStackSkipWithExtras(rollbar.ERR, req, err, 3, ctx)

		return
	}

	h.client.ErrorWithStackSkipWithExtras(rollbar.ERR, err, 3, ctx)
}

func (h *Handler) Close() error {
	return h.client.Close()
}<commit_msg>Make rollbarhandler async by default<commit_after>// Package rollbarhandler provides Rollbar integration.
package rollbarhandler

import (
	"github.com/goph/emperror"
	"github.com/goph/emperror/httperr"
	"github.com/goph/emperror/internal/keyvals"
	"github.com/rollbar/rollbar-go"
)

// Handler is responsible for sending errors to Rollbar.
type Handler struct {
	client *rollbar.Client
}

// New creates a new handler.
func New(token, environment, codeVersion, serverHost, serverRoot string) *Handler {
	return NewFromClient(rollbar.New(token, environment, codeVersion, serverHost, serverRoot))
}

// NewFromClient creates a new handler from a client instance.
func NewFromClient(client *rollbar.Client) *Handler {
	return &Handler{
		client: client,
	}
}

// Handle sends the error to Rollbar.
func (h *Handler) Handle(err error) {
	// Get HTTP request (if any)
	req, httpok := httperr.HTTPRequest(err)

	ctx := keyvals.ToMap(emperror.Context(err))

	// Expose the stackTracer interface on the outer error (if there is stack trace in the error)
	err = emperror.ExposeStackTrace(err)

	// Convert error with stack trace to an internal error type
	if e, ok := err.(stackTracer); ok {
		err = newCauseStacker(e)
	}

	if httpok {
		h.client.RequestErrorWithStackSkipWithExtras(rollbar.ERR, req, err, 3, ctx)

		return
	}

	h.client.ErrorWithStackSkipWithExtras(rollbar.ERR, err, 3, ctx)
}

// Close closes the underlying notifier and waits for asynchronous reports to finish.
func (h *Handler) Close() error {
	return h.client.Close()
}
{'fraction_non_alphanumeric': 0.10976058931860037, 'fraction_numerical': 0.0014732965009208103, 'mean_word_length': 4.6115702479338845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3608054', 'n_tokens_mistral': 925, 'n_tokens_neox': 898, 'n_words': 256}