appsignal

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 9 Imported by: 0

README

AppSignal API Client (Go)

Go Reference

A Go client package that can be used to interact with AppSignal's public GraphQL API.

Installation

go get github.com/Drieam/appsignal-client-go

Usage

Create a client with your AppSignal personal API token. Pass an empty host to use the default (https://appsignal.com/graphql).

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))
	ctx := context.Background()

	viewer, err := client.GetViewer(ctx)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(viewer.Name, viewer.Email)
}

From there the client covers organizations, apps, log sources, log views and log triggers, and lets you send your own queries and mutations for anything it does not wrap yet.

Documentation

The full API reference, with a usage example for every method, lives on pkg.go.dev. The package documentation also covers authentication, pointing the client at a different host, swapping the HTTP client, and telling GraphQL errors apart from HTTP errors.

Tests

To run the E2E tests, you need an AppSignal personal API token. Once acquired, copy the .env.example file to .env and add your API key. You can then run the tests with:

make test-e2e

Makefile

A Makefile wraps the common commands. Run make (or make help) to list them:

Command Description
make build Compile the package
make test Run the unit tests
make test-e2e Run the E2E tests, loading .env if it exists
make cover Run the unit tests and report coverage
make fmt Format the code
make vet Run go vet, including the e2e-tagged files
make tidy Tidy go.mod and go.sum
make check Format, vet and run the unit tests

Documentation

Overview

Package appsignal is a client for AppSignal's public GraphQL API.

It wraps the API's organizations, apps, log sources, log views and log triggers in typed methods on Client, and exposes Client.Query and Client.Mutate for anything the typed methods do not cover yet.

Authentication

Every request is authenticated with an AppSignal personal API token, which you can create under Personal settings in the AppSignal dashboard. Pass it to NewClient and it is sent as a "token" query parameter on each request:

client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))
viewer, err := client.GetViewer(context.Background())

Base URL

An empty host means the public endpoint, HostURL:

client := appsignal.NewClient("", token)

Pass a host to send requests somewhere else.

HTTP client

Requests go through http.DefaultClient unless you replace Client.HTTPClient, which is where you configure timeouts, proxies or a transport that retries:

client := appsignal.NewClient("", token)
client.HTTPClient = &http.Client{Timeout: 10 * time.Second}

Every method takes a context.Context as well, so individual calls can carry their own deadline or be cancelled.

Errors

The API answers with HTTP 200 and an "errors" array when a request is well formed but wrong, for example when an app ID does not exist. Those come back as Errors. Responses with any other status come back as HTTPError. Use errors.As to tell them apart:

_, err := client.GetApp(ctx, "does-not-exist")

var gqlErrs appsignal.Errors
var httpErr *appsignal.HTTPError

switch {
case errors.As(err, &gqlErrs):
	fmt.Println("api error:", gqlErrs)
case errors.As(err, &httpErr):
	fmt.Println("http status:", httpErr.StatusCode)
}

Lookups of a single object return a nil pointer and a nil error when nothing matches, so check both.

Index

Examples

Constants

View Source
const HostURL string = "https://appsignal.com/graphql"
View Source
const Version = "0.1.0" // x-release-please-version

Version is the semantic version of this client library. The trailing comment lets release-please rewrite the literal when it cuts a release; keep it.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ID          string    `json:"id"`
	Environment string    `json:"environment"`
	Name        string    `json:"name"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

type Client

type Client struct {
	HostURL    string
	HTTPClient *http.Client
	Token      string
}

func NewClient

func NewClient(host, token string) *Client

NewClient returns a client that talks to the AppSignal GraphQL API using the given personal API token. Pass an empty host to use the default endpoint.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	// An empty host means the public endpoint, appsignal.HostURL. Pass a real
	// host to point the client at a test server instead.
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	viewer, err := client.GetViewer(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(viewer.Email)
}

func (*Client) CreateApp

func (c *Client) CreateApp(ctx context.Context, input CreateAppInput) (*App, error)

CreateApp adds a new app to an organization and returns the created app.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	app, err := client.CreateApp(context.Background(), appsignal.CreateAppInput{
		OrganizationSlug: "my-organization",
		Name:             "my-app",
		Environment:      "production",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(app.ID)
}

func (*Client) CreateAppLogSource

func (c *Client) CreateAppLogSource(ctx context.Context, input CreateAppLogSourceInput) (*LogSource, error)

CreateAppLogSource adds a new log source to an app and returns the created log source, including the key used to ship logs to it.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	source, err := client.CreateAppLogSource(context.Background(), appsignal.CreateAppLogSourceInput{
		AppID: "6aad24d1ba6bc351255e7cb5",
		Name:  "my-log-source",
		Type:  "custom",
		Fmt:   appsignal.LogSourceFormatJSON,
	})
	if err != nil {
		log.Fatal(err)
	}

	// The key is what you ship log lines with.
	fmt.Println(source.ID, source.Key)
}

func (*Client) CreateAppLogTrigger

func (c *Client) CreateAppLogTrigger(ctx context.Context, input CreateAppLogTriggerInput) (*LogTrigger, error)

CreateAppLogTrigger adds a new log trigger to an app and returns the created log trigger. Leave the optional input fields nil to let the API pick defaults.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// The optional fields are pointers and slices; leave them nil to let the
	// API pick its own defaults.
	description := "Alert when the error log fills up"
	notificationOptions := appsignal.NotificationOptionNthInHour
	notificationTriggerValue := int32(10)

	trigger, err := client.CreateAppLogTrigger(context.Background(), appsignal.CreateAppLogTriggerInput{
		AppID:                    "6aad24d1ba6bc351255e7cb5",
		Name:                     "Too many errors",
		Query:                    "level:error",
		Description:              &description,
		NotificationOptions:      &notificationOptions,
		NotificationTriggerValue: &notificationTriggerValue,
		Severities:               []appsignal.LogSeverity{appsignal.SeverityError, appsignal.SeverityFatal},
		SourceIDs:                []string{"6aad24d1ba6bc351255e7cba"},
		NotifierIDs:              []string{"6aad24d1ba6bc351255e7cbd"},
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(trigger.ID)
}

func (*Client) CreateAppLogView

func (c *Client) CreateAppLogView(ctx context.Context, input CreateAppLogViewInput) (*LogView, error)

CreateAppLogView adds a new log view to an app and returns the created log view. Leave the optional input fields nil to let the API pick defaults.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// The optional fields are pointers and slices; leave them nil to let the
	// API pick its own defaults.
	query := "level:error"

	view, err := client.CreateAppLogView(context.Background(), appsignal.CreateAppLogViewInput{
		AppID:      "6aad24d1ba6bc351255e7cb5",
		Name:       "Errors",
		Query:      &query,
		Severities: []appsignal.LogSeverity{appsignal.SeverityError, appsignal.SeverityFatal},
		SourceIDs:  []string{"6aad24d1ba6bc351255e7cba"},
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(view.ID)
}

func (*Client) DeleteApp

func (c *Client) DeleteApp(ctx context.Context, appID string) (*App, error)

DeleteApp removes an app and returns the app as it was just before deletion.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// The returned app is the one that was just deleted.
	app, err := client.DeleteApp(context.Background(), "6aad24d1ba6bc351255e7cb5")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("deleted", app.Name)
}

func (*Client) DeleteAppLogSource

func (c *Client) DeleteAppLogSource(ctx context.Context, input DeleteAppLogSourceInput) (*LogSource, error)

DeleteAppLogSource removes a log source from an app and returns the log source as it was just before deletion.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	source, err := client.DeleteAppLogSource(context.Background(), appsignal.DeleteAppLogSourceInput{
		AppID:       "6aad24d1ba6bc351255e7cb5",
		LogSourceID: "6aad24d1ba6bc351255e7cba",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("deleted", source.Name)
}

func (*Client) DeleteAppLogTrigger

func (c *Client) DeleteAppLogTrigger(ctx context.Context, input DeleteAppLogTriggerInput) (*LogTrigger, error)

DeleteAppLogTrigger removes a log trigger from an app and returns the log trigger as it was just before deletion.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	trigger, err := client.DeleteAppLogTrigger(context.Background(), appsignal.DeleteAppLogTriggerInput{
		AppID:        "6aad24d1ba6bc351255e7cb5",
		LogTriggerID: "6aad24d1ba6bc351255e7cbc",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("deleted", trigger.Name)
}

func (*Client) DeleteAppLogView

func (c *Client) DeleteAppLogView(ctx context.Context, input DeleteAppLogViewInput) (*LogView, error)

DeleteAppLogView removes a log view from an app and returns the log view as it was just before deletion.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	view, err := client.DeleteAppLogView(context.Background(), appsignal.DeleteAppLogViewInput{
		AppID:     "6aad24d1ba6bc351255e7cb5",
		LogViewID: "6aad24d1ba6bc351255e7cbb",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("deleted", view.Name)
}

func (*Client) GetApp

func (c *Client) GetApp(ctx context.Context, id string) (*App, error)

GetApp looks up a single app by its ID. It returns a nil app when no app with that ID exists.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	app, err := client.GetApp(context.Background(), "6aad24d1ba6bc351255e7cb5")
	if err != nil {
		log.Fatal(err)
	}
	if app == nil {
		log.Fatal("no app with that ID")
	}

	fmt.Println(app.Name, app.Environment)
}

func (*Client) GetAppLogSource

func (c *Client) GetAppLogSource(ctx context.Context, appID string, logSourceID string) (*LogSource, error)

GetAppLogSource looks up a single log source of an app by its ID. It returns a nil log source when the app has no log source with that ID.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	source, err := client.GetAppLogSource(context.Background(),
		"6aad24d1ba6bc351255e7cb5", "6aad24d1ba6bc351255e7cba")
	if err != nil {
		log.Fatal(err)
	}
	if source == nil {
		log.Fatal("no log source with that ID")
	}

	fmt.Println(source.Name, source.Fmt)
}

func (*Client) GetAppLogSources

func (c *Client) GetAppLogSources(ctx context.Context, appID string) ([]LogSource, error)

GetAppLogSources lists every log source of an app.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	sources, err := client.GetAppLogSources(context.Background(), "6aad24d1ba6bc351255e7cb5")
	if err != nil {
		log.Fatal(err)
	}

	for _, source := range sources {
		fmt.Println(source.ID, source.Name, source.Fmt)
	}
}

func (*Client) GetAppLogTriggers

func (c *Client) GetAppLogTriggers(ctx context.Context, appID string) ([]LogTrigger, error)

GetAppLogTriggers lists every log trigger of an app.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	triggers, err := client.GetAppLogTriggers(context.Background(), "6aad24d1ba6bc351255e7cb5")
	if err != nil {
		log.Fatal(err)
	}

	for _, trigger := range triggers {
		fmt.Println(trigger.ID, trigger.Name, trigger.Query)
	}
}

func (*Client) GetAppLogView

func (c *Client) GetAppLogView(ctx context.Context, appID string, logViewID string) (*LogView, error)

GetAppLogView looks up a single log view of an app by its ID. It returns a nil log view when the app has no log view with that ID.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	view, err := client.GetAppLogView(context.Background(),
		"6aad24d1ba6bc351255e7cb5", "6aad24d1ba6bc351255e7cbb")
	if err != nil {
		log.Fatal(err)
	}
	if view == nil {
		log.Fatal("no log view with that ID")
	}

	fmt.Println(view.Name, view.Severities)
}

func (*Client) GetAppLogViews

func (c *Client) GetAppLogViews(ctx context.Context, appID string) ([]LogView, error)

GetAppLogViews lists every log view of an app.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	views, err := client.GetAppLogViews(context.Background(), "6aad24d1ba6bc351255e7cb5")
	if err != nil {
		log.Fatal(err)
	}

	for _, view := range views {
		fmt.Println(view.ID, view.Name, view.Query)
	}
}

func (*Client) GetAppNotifiers

func (c *Client) GetAppNotifiers(ctx context.Context, appID string) ([]Notifier, error)

GetAppNotifiers lists the notifiers configured for an app. Their IDs are what you pass when attaching notifiers to a log trigger.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	notifiers, err := client.GetAppNotifiers(context.Background(), "6aad24d1ba6bc351255e7cb5")
	if err != nil {
		log.Fatal(err)
	}

	// These IDs are what you pass as NotifierIDs on a log trigger.
	for _, notifier := range notifiers {
		fmt.Println(notifier.ID, notifier.Name)
	}
}

func (*Client) GetOrganization

func (c *Client) GetOrganization(ctx context.Context, slug string) (*Organization, error)

GetOrganization looks up a single organization by its slug. It returns a nil organization when no organization with that slug exists.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	organization, err := client.GetOrganization(context.Background(), "my-organization")
	if err != nil {
		log.Fatal(err)
	}
	if organization == nil {
		log.Fatal("no organization with that slug")
	}

	fmt.Println(organization.ID, organization.Name)
}

func (*Client) GetOrganizationApps

func (c *Client) GetOrganizationApps(ctx context.Context, slug string) ([]App, error)

GetOrganizationApps lists every app belonging to the organization with the given slug.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	apps, err := client.GetOrganizationApps(context.Background(), "my-organization")
	if err != nil {
		log.Fatal(err)
	}

	for _, app := range apps {
		fmt.Println(app.ID, app.Name, app.Environment)
	}
}

func (*Client) GetViewer

func (c *Client) GetViewer(ctx context.Context) (*Viewer, error)

GetViewer returns the user that the client's API token belongs to. It is a handy way to check that a token works.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// A quick way to check that a token is valid.
	viewer, err := client.GetViewer(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	if viewer == nil {
		log.Fatal("token does not belong to a user")
	}

	fmt.Println(viewer.Name, viewer.Email)
}

func (*Client) Mutate

func (c *Client) Mutate(ctx context.Context, mutation string, variables map[string]any, out any) error

Mutate sends a GraphQL mutation to the API. It behaves exactly like Query and exists to make calling code read more clearly.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	const mutation = `
mutation CreateApp($organizationSlug: String!, $name: String!, $environment: String!) {
	createApp(organizationSlug: $organizationSlug, name: $name, environment: $environment) {
		id
	}
}
`

	var out struct {
		App struct {
			ID string `json:"id"`
		} `json:"createApp"`
	}

	variables := map[string]any{
		"organizationSlug": "my-organization",
		"name":             "my-app",
		"environment":      "production",
	}
	if err := client.Mutate(context.Background(), mutation, variables, &out); err != nil {
		log.Fatal(err)
	}

	fmt.Println(out.App.ID)
}

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, variables map[string]any, out any) error

Query sends a GraphQL query to the API and decodes the "data" field of the response into out. Pass nil for out to ignore the response body. It returns an *HTTPError for non-200 responses without GraphQL errors, and Errors when the API reports GraphQL errors.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// Any query the typed helpers do not cover can be sent by hand.
	const query = `
query GetAppName($id: String!) {
	app(id: $id) {
		name
	}
}
`

	var out struct {
		App struct {
			Name string `json:"name"`
		} `json:"app"`
	}

	variables := map[string]any{"id": "6aad24d1ba6bc351255e7cb5"}
	if err := client.Query(context.Background(), query, variables, &out); err != nil {
		log.Fatal(err)
	}

	fmt.Println(out.App.Name)
}

func (*Client) UpdateAppLogSource

func (c *Client) UpdateAppLogSource(ctx context.Context, input UpdateAppLogSourceInput) (*LogSource, error)

UpdateAppLogSource changes the name and format of an existing log source and returns the updated log source. Both fields are required, so pass the current value for anything you do not want to change.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// Name and Fmt are both required, so pass the current value for whichever
	// one you are not changing.
	source, err := client.UpdateAppLogSource(context.Background(), appsignal.UpdateAppLogSourceInput{
		AppID:       "6aad24d1ba6bc351255e7cb5",
		LogSourceID: "6aad24d1ba6bc351255e7cba",
		Name:        "my-renamed-log-source",
		Fmt:         appsignal.LogSourceFormatLogfmt,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(source.Name, source.Fmt)
}

func (*Client) UpdateAppLogTrigger

func (c *Client) UpdateAppLogTrigger(ctx context.Context, input UpdateAppLogTriggerInput) (*LogTrigger, error)

UpdateAppLogTrigger changes an existing log trigger and returns the updated log trigger. Only the fields you set on the input are sent; the rest stay as they are.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// Only the fields that are set get sent, so this widens the query and
	// leaves the name, severities and notifiers alone.
	query := "level:error OR level:fatal"

	trigger, err := client.UpdateAppLogTrigger(context.Background(), appsignal.UpdateAppLogTriggerInput{
		AppID:        "6aad24d1ba6bc351255e7cb5",
		LogTriggerID: "6aad24d1ba6bc351255e7cbc",
		Query:        &query,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(trigger.Query)
}

func (*Client) UpdateAppLogView

func (c *Client) UpdateAppLogView(ctx context.Context, input UpdateAppLogViewInput) (*LogView, error)

UpdateAppLogView changes an existing log view and returns the updated log view. Only the fields you set on the input are sent; the rest stay as they are.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	// Only the fields that are set get sent, so this renames the view and
	// leaves its query, columns and severities alone.
	name := "Errors and worse"

	view, err := client.UpdateAppLogView(context.Background(), appsignal.UpdateAppLogViewInput{
		AppID:     "6aad24d1ba6bc351255e7cb5",
		LogViewID: "6aad24d1ba6bc351255e7cbb",
		Name:      &name,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(view.Name)
}

type CreateAppInput

type CreateAppInput struct {
	OrganizationSlug string `json:"organizationSlug"`
	Name             string `json:"name"`
	Environment      string `json:"environment"`
}

type CreateAppLogSourceInput

type CreateAppLogSourceInput struct {
	AppID string          `json:"appId"`
	Fmt   LogSourceFormat `json:"fmt"`
	Name  string          `json:"name"`
	Type  string          `json:"type"`
}

type CreateAppLogTriggerInput

type CreateAppLogTriggerInput struct {
	AppID                    string                        `json:"appId"`
	Name                     string                        `json:"name"`
	Query                    string                        `json:"query"`
	Description              *string                       `json:"description,omitempty"`
	NotificationOptions      *LogTriggerNotificationOption `json:"notificationOptions,omitempty"`
	NotificationTriggerValue *int32                        `json:"notificationTriggerValue,omitempty"`
	Severities               []LogSeverity                 `json:"severities,omitempty"`
	SourceIDs                []string                      `json:"sourceIds,omitempty"`
	NotifierIDs              []string                      `json:"notifierIds,omitempty"`
}

type CreateAppLogViewInput

type CreateAppLogViewInput struct {
	AppID      string        `json:"appId"`
	Name       string        `json:"name"`
	Query      *string       `json:"query,omitempty"`
	Columns    []string      `json:"columns,omitempty"`
	LineHeight *string       `json:"lineHeight,omitempty"`
	Severities []LogSeverity `json:"severities,omitempty"`
	SourceIDs  []string      `json:"sourceIds,omitempty"`
}

type DeleteAppLogSourceInput

type DeleteAppLogSourceInput struct {
	AppID       string `json:"appId"`
	LogSourceID string `json:"logSourceId"`
}

type DeleteAppLogTriggerInput

type DeleteAppLogTriggerInput struct {
	AppID        string `json:"appId"`
	LogTriggerID string `json:"logTriggerId"`
}

type DeleteAppLogViewInput

type DeleteAppLogViewInput struct {
	AppID     string `json:"appId"`
	LogViewID string `json:"logViewId"`
}

type Error

type Error struct {
	Message string `json:"message"`
}

type Errors

type Errors []Error

func (Errors) Error

func (e Errors) Error() string

Error joins all GraphQL error messages into a single semicolon-separated string.

Example
package main

import (
	"context"
	"errors"
	"fmt"
	"os"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", os.Getenv("APPSIGNAL_API_TOKEN"))

	_, err := client.GetApp(context.Background(), "not-a-valid-id")

	// The API answers with 200 and a list of GraphQL errors.
	var gqlErrs appsignal.Errors
	if errors.As(err, &gqlErrs) {
		// Error() joins every message with "; ".
		fmt.Println(gqlErrs.Error())

		for _, gqlErr := range gqlErrs {
			fmt.Println(gqlErr.Message)
		}
	}
}

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Header     http.Header
	Body       []byte
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error describes the unexpected HTTP status, including the response body when there is one.

Example
package main

import (
	"context"
	"errors"
	"fmt"

	appsignal "github.com/Drieam/appsignal-client-go"
)

func main() {
	client := appsignal.NewClient("", "not-a-real-token")

	_, err := client.GetViewer(context.Background())

	// A bad token gets a non-200 response with no GraphQL errors in it.
	var httpErr *appsignal.HTTPError
	if errors.As(err, &httpErr) {
		// The message carries the status and the response body.
		fmt.Println(httpErr.Error())
		fmt.Println(httpErr.StatusCode)
	}
}

type LogSeverity

type LogSeverity string

LogSeverity is the severity level of a log line. It is used by both log triggers and log views.

const (
	SeverityTrace    LogSeverity = "TRACE"
	SeverityDebug    LogSeverity = "DEBUG"
	SeverityInfo     LogSeverity = "INFO"
	SeverityNotice   LogSeverity = "NOTICE"
	SeverityWarn     LogSeverity = "WARN"
	SeverityError    LogSeverity = "ERROR"
	SeverityCritical LogSeverity = "CRITICAL"
	SeverityAlert    LogSeverity = "ALERT"
	SeverityFatal    LogSeverity = "FATAL"
	SeverityUnknown  LogSeverity = "UNKNOWN"
)

type LogSource

type LogSource struct {
	ID   string          `json:"id"`
	Name string          `json:"name"`
	Key  string          `json:"key"`
	Type string          `json:"type"`
	Fmt  LogSourceFormat `json:"fmt"`
}

type LogSourceFormat

type LogSourceFormat string

LogSourceFormat is the log line format of a log source. It maps onto the SourceFormatEnum GraphQL enum.

const (
	LogSourceFormatPlaintext  LogSourceFormat = "PLAINTEXT"
	LogSourceFormatLogfmt     LogSourceFormat = "LOGFMT"
	LogSourceFormatJSON       LogSourceFormat = "JSON"
	LogSourceFormatAutodetect LogSourceFormat = "AUTODETECT"
)

type LogTrigger

type LogTrigger struct {
	ID                       string                       `json:"id"`
	Name                     string                       `json:"name"`
	Query                    string                       `json:"query"`
	SourceIDs                []string                     `json:"sourceIds"`
	ActionType               LogTriggerActionType         `json:"actionType"`
	Description              string                       `json:"description"`
	NotificationOptions      LogTriggerNotificationOption `json:"notificationOptions"`
	NotificationTriggerValue int32                        `json:"notificationTriggerValue"`
	Order                    int32                        `json:"order"`
	Severities               []LogSeverity                `json:"severities"`
	Notifiers                []Notifier                   `json:"notifiers"`
}

func (*LogTrigger) UnmarshalJSON

func (t *LogTrigger) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a log trigger, turning nulls from the API into zero values and empty slices.

type LogTriggerActionType

type LogTriggerActionType string

LogTriggerActionType is the action a log trigger performs when it matches.

const (
	ActionTypeTrigger LogTriggerActionType = "TRIGGER"
	ActionTypeFilter  LogTriggerActionType = "FILTER"
	ActionTypeMetrics LogTriggerActionType = "METRICS"
)

type LogTriggerNotificationOption

type LogTriggerNotificationOption string

LogTriggerNotificationOption controls how often a log trigger notifies.

const (
	NotificationOptionAlways          LogTriggerNotificationOption = "ALWAYS"
	NotificationOptionNever           LogTriggerNotificationOption = "NEVER"
	NotificationOptionFirstInDeploy   LogTriggerNotificationOption = "FIRST_IN_DEPLOY"
	NotificationOptionFirstAfterClose LogTriggerNotificationOption = "FIRST_AFTER_CLOSE"
	NotificationOptionNthInHour       LogTriggerNotificationOption = "NTH_IN_HOUR"
	NotificationOptionNthInDay        LogTriggerNotificationOption = "NTH_IN_DAY"
)

type LogView

type LogView struct {
	ID         string        `json:"id"`
	Name       string        `json:"name"`
	Query      string        `json:"query"`
	Columns    []string      `json:"columns"`
	LineHeight string        `json:"lineHeight"`
	Severities []LogSeverity `json:"severities"`
	SourceIDs  []string      `json:"sourceIds"`
}

func (*LogView) UnmarshalJSON

func (v *LogView) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a log view, turning nulls from the API into empty strings and empty slices.

type Notifier

type Notifier struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Icon string `json:"icon"`
}

type Organization

type Organization struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

type UpdateAppLogSourceInput

type UpdateAppLogSourceInput struct {
	AppID       string          `json:"appId"`
	Fmt         LogSourceFormat `json:"fmt"`
	LogSourceID string          `json:"logSourceId"`
	Name        string          `json:"name"`
}

type UpdateAppLogTriggerInput

type UpdateAppLogTriggerInput struct {
	AppID                    string                        `json:"appId"`
	LogTriggerID             string                        `json:"logTriggerId"`
	Name                     *string                       `json:"name,omitempty"`
	Query                    *string                       `json:"query,omitempty"`
	Description              *string                       `json:"description,omitempty"`
	NotificationOptions      *LogTriggerNotificationOption `json:"notificationOptions,omitempty"`
	NotificationTriggerValue *int32                        `json:"notificationTriggerValue,omitempty"`
	Severities               []LogSeverity                 `json:"severities,omitempty"`
	SourceIDs                []string                      `json:"sourceIds,omitempty"`
	NotifierIDs              []string                      `json:"notifierIds,omitempty"`
}

type UpdateAppLogViewInput

type UpdateAppLogViewInput struct {
	AppID      string        `json:"appId"`
	LogViewID  string        `json:"logViewId"`
	Name       *string       `json:"name,omitempty"`
	Query      *string       `json:"query,omitempty"`
	Columns    []string      `json:"columns,omitempty"`
	LineHeight *string       `json:"lineHeight,omitempty"`
	Severities []LogSeverity `json:"severities,omitempty"`
	SourceIDs  []string      `json:"sourceIds,omitempty"`
}

type Viewer

type Viewer struct {
	ID    string `json:"id"`
	Email string `json:"email"`
	Name  string `json:"name"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL