Skip to content

Instantly share code, notes, and snippets.

@xurizaemon
Last active March 19, 2025 03:11
Show Gist options
  • Save xurizaemon/d85b02ef39a6bff8a457263a189ab38c to your computer and use it in GitHub Desktop.
Save xurizaemon/d85b02ef39a6bff8a457263a189ab38c to your computer and use it in GitHub Desktop.
Generate a sample report to GlitchTip
#!/usr/bin/env bash
# Get next three values from GlitchTip project settings "Security endpoint".
# /api/$PROJECT_ID/security/?glitchtip_key=PUBLIC_KEY
# GLITCHTIP_URL=https://app.glitchtip.com/
GLITCHTIP_URL=https://glitchtip.example.com/
PROJECT_ID=1234
PUBLIC_KEY=4373a702c4801b32b2f30a7a03e04b0d
REPORT_URL="${GLITCHTIP_URL}api/${PROJECT_ID}/envelope/?sentry_key=${PUBLIC_KEY}"
# Adjust if required.
SOURCE_URL=https://example.com
RELEASE=none
ENVIRONMENT=test
# Making up data for the below.
EVENT_ID=$( uuidgen | sed -e 's#-##g' )
TRACE_ID=$( uuidgen | sed -e 's#-##g' )
SPAN_ID=$( uuidgen | sed -e 's#.*-##g' )
DATETEXT=$( date )
DATETIME=$( date -u +"%Y-%m-%dT%H:%M:%S.000Z" )
TIMESTAMP=$( date +%s ).000
# Required value.
PUBLIC_KEY=$( echo hunter22 | md5sum )
read -r -d '' DATA <<EOF
{"event_id":"${EVENT_ID}","sent_at":"${DATETIME}","trace":{"environment":"${ENVIRONMENT}","release":"${RELEASE}","public_key":"${PUBLIC_KEY}","trace_id":"${TRACE_ID}"}}
{"type":"event"}
{"message": "Test message ${DATETEXT}.","level": "info","event_id": "${EVENT_ID}","platform": "none","request": {"url": "${SOURCE_URL}","headers": {}},"timestamp": $TIMESTAMP,"environment": "${ENVIRONMENT}","release": "${RELEASE}","breadcrumbs": [],"contexts": {"trace": {"trace_id": "${TRACE_ID}","span_id": "${SPAN_ID}"}}}
EOF
# echo $DATA
curl -v "${REPORT_URL}" -X POST -H 'Content-Type: text/plain;charset=UTF-8' -H 'Accept: application/json' --data-raw "${DATA}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment