Files
4102219754 fork: own SigNoz platform deps under hanzoai + repath off upstream brand (Phase 1) (#9)
* fork: own SigNoz platform deps under hanzoai, repath imports off upstream brand

Phase 1 of the full-fork mandate: eliminate upstream-branded SigNoz modules,
own them as public hanzoai forks, and repath all imports to hanzoai paths.

Owned deps (new public hanzoai forks, module renamed to hanzoai path):
  github.com/SigNoz/signoz-otel-collector v0.144.3
    -> github.com/hanzoai/signoz-otel-collector v0.144.6 (module renamed)
  github.com/SigNoz/clickhouse-go-mock v0.14.0
    -> github.com/hanzoai/clickhouse-go-mock v0.14.1 (module renamed)
  github.com/SigNoz/govaluate v0.0.0-20240203125216-988004ccc7fd
    -> github.com/hanzoai/govaluate v0.1.0 (module renamed)
  github.com/SigNoz/expr (replace target for github.com/expr-lang/expr)
    -> github.com/hanzoai/expr v1.17.8 (upstream module path preserved,
       consumed via replace exactly like the prior SigNoz/expr fork)

In-repo repath: the vendored SigNoz source tree in pkg/, ee/, cmd/ is now
self-referenced as github.com/hanzoai/o11y/... instead of
github.com/SigNoz/signoz/... (1300+ import lines across 377 files), matching
the 750 files already on the hanzoai path. Zero SigNoz-branded module
references remain in go.mod or any .go import.

Generic ecosystem libraries (golang.org/x, google.golang.org, prometheus,
opentelemetry, gin, cobra, luxfi/*, etc.) are left untouched — only the
SigNoz platform fork is owned.

Pre-existing (NOT introduced here): origin/main does not `go build ./...`
because 22 packages are imported but absent from the vendored tree; 14 of
them (roletypes, grammar, cloudintegrations, resourcefilter, integrationtypes,
metricsexplorer, metrics_explorer, times, agg_rewrite, bucket_cache,
sqlitesqlstore, sqlschema/postgressqlschema, sqlstore/postgressqlstore,
cloudintegrations/services) exist in no upstream SigNoz version and must be
vendored into hanzoai/o11y from hanzoai/signoz@770f464f to finish. This
repath is orthogonal to that gap.

* docs(LLM.md): fork boundary map + pre-existing compile-gap inventory

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-30 18:05:03 -07:00

101 lines
2.7 KiB
Go

package loghandler
import (
"bytes"
"context"
"encoding/json"
"log/slog"
"testing"
"github.com/hanzoai/o11y/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestException(t *testing.T) {
testCases := []struct {
name string
attrs []slog.Attr
exceptionType string
exceptionCode string
exceptionMessage string
hasException bool
}{
{
name: "PkgError",
attrs: []slog.Attr{
errors.Attr(errors.New(errors.TypeNotFound, errors.MustNewCode("test_code"), "resource not found")),
},
exceptionType: "not-found",
exceptionCode: "test_code",
exceptionMessage: "resource not found",
hasException: true,
},
{
name: "StdlibError",
attrs: []slog.Attr{
errors.Attr(errors.Newf(errors.TypeInternal, errors.MustNewCode("internal"), "something went wrong")),
},
exceptionType: "internal",
exceptionCode: "internal",
exceptionMessage: "something went wrong",
hasException: true,
},
{
name: "WrappedPkgError",
attrs: []slog.Attr{
errors.Attr(errors.Wrapf(errors.New(errors.TypeNotFound, errors.MustNewCode("not_found"), "db connection failed"), errors.TypeInternal, errors.MustNewCode("db_error"), "failed to fetch user")),
},
exceptionType: "internal",
exceptionCode: "db_error",
exceptionMessage: "failed to fetch user",
hasException: true,
},
{
name: "NoError",
attrs: []slog.Attr{
slog.String("key", "value"),
},
hasException: false,
},
{
name: "ExceptionKeyWithNonError",
attrs: []slog.Attr{
slog.String("exception", "not an error type"),
},
hasException: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
buf := bytes.NewBuffer(nil)
logger := slog.New(&handler{
base: slog.NewJSONHandler(buf, &slog.HandlerOptions{Level: slog.LevelDebug}),
wrappers: []Wrapper{NewException()},
})
logger.LogAttrs(context.Background(), slog.LevelError, "operation failed", tc.attrs...)
m := make(map[string]any)
err := json.Unmarshal(buf.Bytes(), &m)
require.NoError(t, err)
assert.Equal(t, "operation failed", m["msg"])
if tc.hasException {
assert.Equal(t, tc.exceptionType, m["exception.type"])
assert.Equal(t, tc.exceptionCode, m["exception.code"])
assert.Equal(t, tc.exceptionMessage, m["exception.message"])
stacktrace, ok := m["exception.stacktrace"].(string)
require.True(t, ok)
assert.Contains(t, stacktrace, "exception_test.go:")
} else {
assert.Nil(t, m["exception.type"])
assert.Nil(t, m["exception.code"])
assert.Nil(t, m["exception.message"])
assert.Nil(t, m["exception.stacktrace"])
}
})
}
}