An open API service indexing awesome lists of open source software.

https://github.com/shaharia-lab/telemetry-collector

A telemetry collector for receiving telemetry data and forward to a specified endpoint (i.e: Honeycomb)
https://github.com/shaharia-lab/telemetry-collector

honeycomb open-source open-telemetry otel telemetry

Last synced: about 1 month ago
JSON representation

A telemetry collector for receiving telemetry data and forward to a specified endpoint (i.e: Honeycomb)

Awesome Lists containing this project

README

          

# Telemetry Package

A Go package for sending telemetry events following OpenTelemetry standards.

## Features

- OpenTelemetry-compatible event structure
- Synchronous and asynchronous sending methods
- Automatic addition of required fields (timestamp, severity numbers)
- Configurable service name
- Helper methods for common event types
- Background processing for non-blocking operations

## Installation

```bash
go get github.com/shaharia-lab/telemetry-collector
```

## Usage

### Basic Setup

```go
import (
"context"
"time"
"github.com/shaharia-lab/telemetry-collector"
)

func main() {
// Create a collector with endpoint and service name
collector := telemetry.NewCollector(
"https://telemetry-service.example.com/telemetry/event",
"my-service"
)
defer collector.Close() // Ensure proper shutdown

// Your application code...
}
```

### Sending Events Synchronously

```go
// Send a synchronous event with full control over fields
err := collector.SendSync(context.Background(), &telemetry.TelemetryEvent{
Name: "user.login",
TraceID: "trace-123",
SpanID: "span-456",
SeverityText: telemetry.SeverityInfo,
Body: "User logged in successfully",
Attributes: map[string]string{
"user_id": "user-123",
"region": "us-west",
},
})
if err != nil {
log.Printf("Failed to send event: %v", err)
}
```

### Sending Events Asynchronously

```go
// Send an asynchronous event (non-blocking)
collector.SendAsync(&telemetry.TelemetryEvent{
Name: "background.task",
TraceID: "trace-789",
SpanID: "span-012",
SeverityText: telemetry.SeverityDebug,
Body: "Background task started",
})
```

### Using Helper Methods

```go
// Using the helper method for info events
collector.InfoEvent(
context.Background(),
"app.startup",
"Application started",
map[string]string{"version": "1.0.0"}
)
```

## Severity Levels

The package includes standard severity levels:
- `SeverityTrace` (1)
- `SeverityDebug` (5)
- `SeverityInfo` (9)
- `SeverityWarn` (13)
- `SeverityError` (17)
- `SeverityFatal` (21)

## Event Structure

Events follow the OpenTelemetry format:

```go
type TelemetryEvent struct {
Name string `json:"name"`
TimeUnixNano int64 `json:"timeUnixNano"`
TraceID string `json:"traceId"`
SpanID string `json:"spanId"`
SeverityText Severity `json:"severityText"`
SeverityNumber int `json:"severityNumber"`
Body string `json:"body"`
Attributes map[string]string `json:"attributes,omitempty"`
Resource Resource `json:"resource"`
}
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.