Telemetry
Home
  • Getting Started
    • Quick Start
  • SDKs
    • Javascript
    • Python
    • Rust
    • Go
    • Dart
  • API Reference
    • Log
    • Query
    • Delete
  • Discussion Topics
    • Telemetry architecture
    • Adding Telemetry to Your Codebase
    • Creating Dashboards
    • Schema Evolution
    • Querying Nested JSON
    • Working with Timestamps
    • CamelCase vs snake_case
    • Automating Incidence Response
  • Guides
    • Tracking OpenAI Costs
    • Revenue A/B Tests
    • Monitoring Website Uptime
    • Queue Worker Observability
    • Visualizing Distributions
    • Measuring Conversion Rates
    • Analyzing Webserver Errors
    • Profiling Code Execution
Powered by GitBook
On this page
  1. SDKs

Go

Installation

To install the Telemetry SDK for Go, use the following command:

go get github.com/telemetry-sh/telemetry-go

Usage

Import Library

import (
    "fmt"
    "log"
    "time"

    "github.com/telemetry-sh/telemetry-go"
)

Initialize Client

t := telemetry.NewTelemetry()
t.Init("YOUR_API_KEY") 

Log Some Data

Telemetry automatically creates tables when data is logged. In the following example, we log some Uber ride data to a table called uber_rides. Telemetry will automatically create this table and its corresponding schema with columns: city, price, and timestamp.

data := map[string]interface{}{
    "city":      "paris",
    "price":     42,
    "timestamp": time.Now().Format(time.RFC3339), // Dynamically generate ISO 8601 timestamp
}

logResponse, err := t.Log("uber_rides", data)
if err != nil {
    log.Fatal("Error logging data:", err)
}
fmt.Println("Log response:", logResponse)

Query Some Data

You can query the data using SQL through the query API.

query := `
    SELECT
        city,
        AVG(price) AS average_price
    FROM
        uber_rides
    GROUP BY
        city
`

queryResponse, err := t.Query(query)
if err != nil {
    log.Fatal("Error querying data:", err)
}
fmt.Println("Query response:", queryResponse)
PreviousRustNextDart

Last updated 9 months ago