Verify Go SDK events

이 페이지는 아직 귀하의 언어로 번역되지 않았습니다. 현재 작업 중이므로 곧 다시 확인해 주십시오.

An event moves through four stages between your Track() call and Amplitude's servers. Verify each stage in order. The first stage where the event looks wrong is where the problem is.

For problems common to every Amplitude SDK, go to SDK troubleshooting and debugging. If behavior changed after an SDK upgrade, check the Go SDK releases on GitHub.

Turn on debug logging

The default logger has no log levels. It writes every message, Debug included, to standard error with Go's standard log package. You don't need to turn anything on: run the client with the default Logger and read standard error.

go
package main

import "github.com/amplitude/analytics-go/amplitude"

func main() {
	config := amplitude.NewConfig("AMPLITUDE_API_KEY")
	client := amplitude.NewClient(config)
	defer client.Shutdown()

	client.Track(amplitude.Event{
		EventType:       "Sign Up Completed",
		UserID:          "user-12345",
		EventProperties: map[string]interface{}{"plan": "starter"},
	})
}

Each line starts with amplitude-analytics - , a timestamp, and the level: Debug:, Info:, Warn:, or Error:. Filter standard error on that prefix.

The default logger writes your API key

On every upload, the default logger writes the full request body, including api_key, at the Debug level. Because the default logger doesn't filter levels, this happens in production too. Before you deploy, set a Logger that drops Debug messages. Go to Control logging.

Check what the SDK captured

Each Track(), Identify(), GroupIdentify(), SetGroup(), and Revenue() call logs the event it accepted:

text
amplitude-analytics - 2026/11/11 13:04:25 Debug: Client initialized
amplitude-analytics - 2026/11/11 13:04:25 Debug: Track event:
	{EventType:Sign Up Completed EventOptions:{UserID:user-12345 DeviceID: ...} EventProperties:map[plan:starter] ...}

Check the log for these problems:

Check how plugins transformed the event

The SDK runs plugins in this order: Before plugins, then Enrichment plugins, then every Destination plugin. The built-in context plugin is a Before plugin that NewClient() adds before any of yours. It sets time and insert_id when they're empty, and always sets library. A plugin that returns nil drops the event. If a plugin panics, the SDK logs Error: Panic in plugin <name>.Execute: ... and passes the event on unchanged.

To inspect events in code, add an Enrichment plugin. It runs after the built-in context plugin, so it sees the fields the SDK added:

go
package main

import (
	"encoding/json"
	"log"

	"github.com/amplitude/analytics-go/amplitude"
)

type inspectPlugin struct{}

func (p *inspectPlugin) Name() string                { return "inspect-events" }
func (p *inspectPlugin) Type() amplitude.PluginType  { return amplitude.PluginTypeEnrichment }
func (p *inspectPlugin) Setup(config amplitude.Config) {}

func (p *inspectPlugin) Execute(event *amplitude.Event) *amplitude.Event {
	b, _ := json.Marshal(event)
	log.Printf("Amplitude event: %s", b)
	return event
}

func main() {
	config := amplitude.NewConfig("AMPLITUDE_API_KEY")
	client := amplitude.NewClient(config)
	defer client.Shutdown()

	client.Add(&inspectPlugin{})

	client.Track(amplitude.Event{
		EventType:       "Sign Up Completed",
		UserID:          "user-12345",
		EventProperties: map[string]interface{}{"plan": "starter"},
	})
}

The plugin prints the event as the SDK sends it:

json
{
  "event_type": "Sign Up Completed",
  "user_id": "user-12345",
  "time": 1794431065800,
  "insert_id": "d99fc12f-77d3-40c5-9bb6-6a082fdd0a80",
  "library": "amplitude-go/1.3.1",
  "event_properties": { "plan": "starter" }
}

Remove the inspection plugin when you finish, so event payloads don't reach your production logs.

Check what the SDK sent

A server process has no Network tab. The default logger already writes each request body before the SDK sends it, on a payloadBytes line:

text
amplitude-analytics - 2026/11/11 13:04:25 Debug: payloadBytes:
	{"api_key":"AMPLITUDE_API_KEY","events":[{"event_type":"Sign Up Completed","user_id":"user-12345","time":1794431065800,"insert_id":"d99fc12f-...","library":"amplitude-go/1.3.1","event_properties":{"plan":"starter"}}]}
amplitude-analytics - 2026/11/11 13:04:25 Info: HTTP response code: 200 OK
amplitude-analytics - 2026/11/11 13:04:25 Info: HTTP response body: {"code":200,"events_ingested":1,...}

The SDK sends plain JSON. It doesn't compress request bodies. An options object with min_id_length appears only when you set MinIDLength.

To inspect requests without sending them to Amplitude, for example in a test, point ServerURL at a local server that answers like Amplitude:

go
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/http/httptest"

	"github.com/amplitude/analytics-go/amplitude"
)

func main() {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		body, _ := io.ReadAll(r.Body)
		fmt.Println(r.Method, r.URL.Path, string(body))
		w.Write([]byte(`{"code":200,"events_ingested":1}`))
	}))
	defer server.Close()

	config := amplitude.NewConfig("AMPLITUDE_API_KEY")
	config.ServerURL = server.URL + "/2/httpapi"
	client := amplitude.NewClient(config)

	client.Track(amplitude.Event{EventType: "Sign Up Completed", UserID: "user-12345"})
	client.Shutdown()
}

The server prints one POST /2/httpapi line per upload, followed by the request body. Remove ServerURL when you finish, so events go to Amplitude again.

Check what Amplitude received

Read the upload result

Set ExecuteCallback to receive one ExecuteResult for each event after its upload finishes. The SDK calls it for events Amplitude accepted and for events it stopped retrying. It doesn't call it for events it plans to retry.

go
package main

import (
	"log"

	"github.com/amplitude/analytics-go/amplitude"
)

func main() {
	config := amplitude.NewConfig("AMPLITUDE_API_KEY")
	config.ExecuteCallback = func(result amplitude.ExecuteResult) {
		log.Printf("%s: %d %s", result.Event.EventType, result.Code, result.Message)
	}
	client := amplitude.NewClient(config)
	defer client.Shutdown()

	client.Track(amplitude.Event{EventType: "Sign Up Completed", UserID: "user-12345"})
}

The callback runs in its own goroutine. In version 1.3.1 and later, Shutdown() waits for running callbacks to return. For a failed event, the SDK also logs Error: <message>: code=<code>, events=[...].

For how the SDK retries each status, go to How the SDK uploads events.

Find the event in Amplitude

  1. In Amplitude, open User Lookup and search for the user_id or device_id you sent.
  2. Open the Activity tab and turn on Live event updates.
  3. Find the event by name, and confirm its properties.

If the upload result is 200 but the event doesn't appear, check these settings:

  • The API key belongs to the project you're viewing.
  • The project's data center matches ServerZone.

이 내용이 도움이 되었나요?

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

이 페이지에서