Verify Python 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 Amplitude-Python changelog.

Turn on debug logging

The SDK logs through Python's logging module on the logger named amplitude. Validation errors log at ERROR, and the result of each upload logs at INFO, one line per event. Python hides INFO by default, so set the level while you verify:

python
import logging
from amplitude import Amplitude, BaseEvent

logging.basicConfig(level=logging.INFO)
logging.getLogger("amplitude").setLevel(logging.DEBUG)

client = Amplitude("AMPLITUDE_API_KEY")
client.track(BaseEvent("Report Exported", user_id="user-12345"))
# INFO:amplitude:Event sent successfully.

Each per-event log record stores the event and the response code in the event and code attributes of the LogRecord. A custom handler or filter can read these attributes. To move the per-event lines to DEBUG, or turn them off, set event_log_level. event_log_level requires 1.3.0 or later.

Check what the SDK captured

track(), identify(), group_identify(), and revenue() validate their input in your thread, before the SDK queues anything. A rejected call logs one of these lines and sends nothing:

One failure produces no log line: when a property dictionary contains a value of an unsupported type, such as a datetime or a custom object, the SDK discards the whole dictionary. Check the event object before you track it:

python
from datetime import datetime
from amplitude import BaseEvent

event = BaseEvent(
    "Report Exported",
    user_id="user-12345",
    event_properties={"exported_at": datetime.now()},
)
print(event.event_properties)
# None: datetime isn't a supported value type, so the SDK discarded the dictionary

Supported property values are strings, numbers, booleans, Enum members (sent as their .value), None (dropped from the payload), lists of those, and nested dictionaries. Convert anything else, for example datetime.now().isoformat().

Check how plugins transformed the event

After validation, each event passes through the plugin pipeline in a fixed order, in the thread that called track():

  1. Before plugins (PluginType.BEFORE): The built-in context plugin sets time and insert_id if they're empty, adds the configured plan and ingestion_metadata, and sets library to amplitude-python/<version>.
  2. Enrichment plugins (PluginType.ENRICHMENT): Your enrichment plugins run here, in the order you added them. A plugin that returns None drops the event.
  3. Destination plugins (PluginType.DESTINATION): The built-in Amplitude destination checks that the event has an ID, then queues it. Each destination receives its own copy of the event.

To see the event exactly as the destinations receive it, add an enrichment plugin after your own plugins. The following plugin prints each event and returns the event unchanged:

python
from amplitude import Amplitude, BaseEvent, EventPlugin, PluginType

class InspectEvents(EventPlugin):
    def __init__(self):
        super().__init__(PluginType.ENRICHMENT)

    def execute(self, event):
        print("final event:", event)
        return event

client = Amplitude("AMPLITUDE_API_KEY")
client.add(InspectEvents())
client.track(BaseEvent("Report Exported", user_id="user-12345"))

print(event) writes the event as the JSON object the SDK uploads. Remove the plugin with client.remove(plugin) when you're done. Exceptions inside a plugin don't reach your code. The SDK logs each exception as Error for apply ENRICHMENT plugin for event ... with a traceback. The SDK then continues with the event as it was before that plugin ran.

Check what the SDK sent

The SDK uploads with an HTTPS POST from a background thread. The SDK has no request log, so check the URL and the event body directly.

client.configuration.server_url returns the URL the client uses. The SDK uploads queued events every flush_interval_millis (10 seconds by default), or sooner when flush_queue_size (200 by default) events are ready. Each request carries up to flush_queue_size events. Request bodies are uncompressed JSON, so a proxy or packet capture shows them as sent.

The request body has this shape:

python
from amplitude import Amplitude, BaseEvent

client = Amplitude("AMPLITUDE_API_KEY")
client.track(
    BaseEvent(
        "Sign Up Completed",
        user_id="user-12345",
        event_properties={"plan": "starter"},
    )
)
json
{
  "api_key": "AMPLITUDE_API_KEY",
  "events": [
    {
      "event_type": "Sign Up Completed",
      "user_id": "user-12345",
      "event_properties": { "plan": "starter" },
      "time": 1762780800000,
      "insert_id": "5f1c8e2a-9b0d-4c6e-8f3a-2d7b1e4c9a60",
      "library": "amplitude-python/1.3.0"
    }
  ]
}

The SDK sets only the fields you pass plus time, insert_id, and library. The SDK doesn't add device, platform, IP, or location fields. To attribute an event to your end user's location rather than your server's, set ip or the location fields on the event. When you set min_id_length, the body also carries "options": {"min_id_length": <n>}.

Check what Amplitude received

Read the upload result

The client-level callback in Config and the callback argument of an individual event run when the event reaches a final upload result: success or final failure. Both callbacks receive (event, code, message):

python
from amplitude import Amplitude, BaseEvent

def on_result(event, code, message):
    print(event.event_type, code, message)

client = Amplitude("AMPLITUDE_API_KEY")
client.track(BaseEvent("Report Exported", user_id="user-12345", callback=on_result))
# Report Exported 200 Event sent successfully.

A rejected API key (400 with Invalid API key: ... from the server) doesn't reach the callback. The SDK logs Invalid API Key at ERROR and drops the batch.

A 200 response means Amplitude's ingestion API accepted the event. Amplitude can still exclude an accepted event from analysis later, for example when a block filter matches it.

Find the event in Amplitude

  1. Open User Lookup and search for the event's user_id, or its device_id if you sent only that.
  2. Select the Activity tab and turn on Live event updates.
  3. Open the event and compare its properties with the final event output from your inspection plugin.

For events from many users, use the Ingestion Debugger to review accepted and rejected requests for the project. Charts can take a few minutes longer to include new events than User Lookup does.

これは役に立ちましたか?

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.

このページでは