Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/telemetry/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package telemetry

import (
"net/http"
"strings"

"github.com/go-errors/errors"
Expand Down Expand Up @@ -41,6 +42,9 @@ func NewClient(apiKey string, endpoint string, baseProperties map[string]any, fa
if endpoint != "" {
config.Endpoint = endpoint
}
// Preserve the active process-wide transport, which may be wrapped by debug.NewTransport()
// instead of assuming http.DefaultTransport is always a *http.Transport.
config.Transport = http.DefaultTransport
client, err := factory(apiKey, config)
if err != nil {
return nil, errors.Errorf("failed to initialize posthog client: %w", err)
Expand Down
16 changes: 16 additions & 0 deletions internal/telemetry/client_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package telemetry

import (
"net/http"
"testing"

"github.com/posthog/posthog-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/supabase/cli/internal/debug"
)

type fakeQueue struct {
Expand Down Expand Up @@ -51,6 +53,20 @@ func TestNewClient(t *testing.T) {
assert.NoError(t, client.Capture("device-1", EventCommandExecuted, map[string]any{"command": "login"}, nil))
assert.NoError(t, client.Close())
})
t.Run("works when debug wraps the default transport", func(t *testing.T) {
original := http.DefaultTransport
http.DefaultTransport = debug.NewTransport()
t.Cleanup(func() {
http.DefaultTransport = original
})

client, err := NewClient("phc_test", "https://eu.i.posthog.com", map[string]any{"platform": "cli"}, nil)

require.NoError(t, err)
require.NotNil(t, client)
assert.True(t, client.Enabled())
assert.NoError(t, client.Close())
})
}

func TestCaptureMergesBasePropertiesAndGroups(t *testing.T) {
Expand Down
Loading