> For the complete documentation index, see [llms.txt](https://docs.telemetry.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.telemetry.sh/sdks/go.md).

# Go

### Installation

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

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

#### Usage

**Import Library**

```go
import (
    "fmt"
    "log"
    "time"

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

**Initialize Client**

```go
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`.

```go
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.

```go
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)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.telemetry.sh/sdks/go.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
