Files
zeekay b9f9cdf918 feat: bump o11y fork to latest SigNoz — full re-sync, builds green (§4c retained)
Re-sync the entire SigNoz-derived Go tree to a clean fork of latest SigNoz
main (upstream 3e6339019), eliminating the version-skew that broke
`go build ./...` (mixed-era packages, ~14 imported-but-absent packages,
partial signoz->o11y / clickhouse->datastore rebrands, self-import cycle,
duplicate package decls).

- pkg/ + cmd/ wholesale replaced with latest SigNoz; imports rewritten
  github.com/SigNoz/signoz/ -> github.com/hanzoai/o11y/.
- Adopt SigNoz's CURRENT structure (resourcefilter->telemetryresourcefilter,
  integrationtypes->cloudintegrationtypes, roletypes/grammar/times folded in
  upstream); old paths dropped.
- Fork deps repathed to hanzoai + bumped: signoz-otel-collector v0.144.6,
  clickhouse-go-mock v0.14.1, govaluate v0.1.0; expr-lang/expr => hanzoai/expr
  v1.17.8 (replace). go.mod reconciled from latest SigNoz; go.sum re-tidied.
- ee/ + cmd/enterprise stripped — o11y stays MIT-only; community edition
  imports no ee packages.
- Preserved o11y additions: module path github.com/hanzoai/o11y, mount.go
  (cloud.Register/zip mount adapter, HIP-0106), NOTICE + LICENSE (SigNoz §4c
  attribution retained; upstream pkg files are headerless per SigNoz convention).
- Reverted o11y cosmetic renames (o11y*/datastore*) and experimental originals
  (authz/iamauthz, billing, zapreceiver, zapmetricreceiver) to SigNoz canonical
  to kill the skew; snapshots retained in git history for re-layering.

go build ./... = exit 0. go vet clean except benign "unreachable code" in
generated ANTLR parser files (inherited from upstream).
2026-07-02 14:20:32 -07:00

97 lines
2.9 KiB
Go

package smtpemailing
import (
"context"
"net/mail"
"github.com/hanzoai/o11y/pkg/emailing"
"github.com/hanzoai/o11y/pkg/emailing/templatestore/filetemplatestore"
"github.com/hanzoai/o11y/pkg/errors"
"github.com/hanzoai/o11y/pkg/factory"
"github.com/hanzoai/o11y/pkg/smtp/client"
"github.com/hanzoai/o11y/pkg/types/emailtypes"
)
type provider struct {
settings factory.ScopedProviderSettings
store emailtypes.TemplateStore
client *client.Client
config emailing.Config
}
func NewFactory() factory.ProviderFactory[emailing.Emailing, emailing.Config] {
return factory.NewProviderFactory(factory.MustNewName("smtp"), New)
}
func New(ctx context.Context, providerSettings factory.ProviderSettings, config emailing.Config) (emailing.Emailing, error) {
settings := factory.NewScopedProviderSettings(providerSettings, "github.com/hanzoai/o11y/pkg/emailing/smtpemailing")
// Try to create a template store. If it fails, use an empty store.
store, err := filetemplatestore.NewStore(ctx, config.Templates.Directory, emailtypes.Templates, settings.Logger())
if err != nil {
settings.Logger().ErrorContext(ctx, "failed to create template store, using empty store", errors.Attr(err))
store = filetemplatestore.NewEmptyStore()
}
client, err := client.New(
config.SMTP.Address,
settings.Logger(),
client.WithFrom(config.SMTP.From),
client.WithHello(config.SMTP.Hello),
client.WithHeaders(config.SMTP.Headers),
client.WithTLS(client.TLS{
Enabled: config.SMTP.TLS.Enabled,
InsecureSkipVerify: config.SMTP.TLS.InsecureSkipVerify,
CAFilePath: config.SMTP.TLS.CAFilePath,
KeyFilePath: config.SMTP.TLS.KeyFilePath,
CertFilePath: config.SMTP.TLS.CertFilePath,
}),
client.WithAuth(client.Auth{
Username: config.SMTP.Auth.Username,
Password: config.SMTP.Auth.Password,
Secret: config.SMTP.Auth.Secret,
Identity: config.SMTP.Auth.Identity,
}),
)
if err != nil {
return nil, err
}
return &provider{
settings: settings,
store: store,
client: client,
config: config,
}, nil
}
func (provider *provider) SendHTML(ctx context.Context, to string, subject string, templateName emailtypes.TemplateName, data map[string]any) error {
toAddress, err := mail.ParseAddressList(to)
if err != nil {
return err
}
template, err := provider.store.Get(ctx, templateName)
if err != nil {
return err
}
// if no data is provided, create an empty map to prevent a panic when we add the format, to, and subject data
if data == nil {
data = make(map[string]any)
}
// the following are overridden if provided in the data map
data["format"] = provider.config.Templates.Format
data["to"] = to
data["subject"] = subject
content, err := emailtypes.NewContent(template, data)
if err != nil {
provider.settings.Logger().ErrorContext(ctx, "failed to create email content", errors.Attr(err))
return err
}
return provider.client.Do(ctx, toAddress, subject, client.ContentTypeHTML, content)
}