Coder Social home page Coder Social logo

go-sentry-api's Introduction

Go Sentry API

godoc Build Status

This is a library that implements a client in go for the sentry api. It supports all the endpoints and can do a good bit. For a full reference you can check the godoc link above.

Usage

Initialization and Create New DSN Key

import (
	"fmt"

	"github.com/atlassian/go-sentry-api"
)
// Auth token is always required, secondary is endpoint and third is timeout defaults 60 seconds
client, _:= sentry.NewClient("yourauthtokengoeshere", nil, nil)

// Fetch your organization
org, err := client.GetOrganization("sentry")
if err != nil {
	panic(err)
}

// Fetch a project you already made
project, err := client.GetProject(org, "my-project-slug")
if err != nil {
	panic(err)
}

// Create a new Client DSN via the API
key, err := client.CreateClientKey(org, project, "example-dsn")
if err != nil {
	panic(err)
}
fmt.Printf(key.DSN.Secret)

Installation

go get github.com/atlassian/go-sentry-api

Documentation

godoc

Tests

To run tests you can setup a local sentry instance via docker. There is a makefile command called make devenv which will setup all of the containers.

Once complete you can then setup a environment var of SENTRY_AUTHTOKEN and then run make test which should go through and create and run all tests aginst localhost:8080

Contributors

Pull requests, issues and comments welcome. For pull requests:

  • Add tests for new features and bug fixes
  • Follow the existing style
  • Separate unrelated changes into multiple pull requests

See the existing issues for things to start contributing. For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change. Atlassian requires contributors to sign a Contributor License Agreement, known as a CLA. This serves as a record stating that the contributor is entitled to contribute the code/documentation/translation to the project and is willing to have it used in distributions and derivative works (or is willing to transfer ownership).

Prior to accepting your contributions we ask that you please follow the appropriate link below to digitally sign the CLA. The Corporate CLA is for those who are contributing as a member of an organization and the individual CLA is for those contributing as an individual.

License

Copyright (c) 2017 Atlassian and others. Apache 2.0 licensed, see LICENSE.txt file.

go-sentry-api's People

Contributors

chenzhihao avatar cwood avatar databus23 avatar degzhaus avatar irisgve avatar korotin avatar leahrivkin avatar moriyoshi avatar motecshine avatar motoronik avatar spectrogram avatar taiidani avatar vetinari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sentry-api's Issues

Paging example

Could you add an example of how to page in the README? I'm trying to pull all the issues for all projects in my org and count the number of errors over the past 24 hours. Here's an example for the first page of info:

package main

import (
	"fmt"
	"github.com/atlassian/go-sentry-api"
	"strconv"
	"strings"
)

func main() {

	client, err := sentry.NewClient("authtoken", nil, nil)
	org, err := client.GetOrganization("drone-deploy")
	if err != nil {
		panic(err)
	}

	projects, err := client.GetProjects()
	if err != nil {
		panic(err)
	}

	for _, project := range projects {
		query := "is:resolved"
		issues, _, err := client.GetIssues(org, project, nil, nil, &query)
		if err != nil {
			fmt.Println("Skipping " + project.Name)
		}

		total := float64(0)
		for _, issue := range issues {

			stats := *issue.Stats.TwentyFourHour

			for _, stat := range stats {
				issueId := *issue.ID
				issueCount := *issue.Count
				s := []string{project.Name, issueId, issueCount,
					strconv.FormatFloat(stat[0], 'f', -1, 64),
					strconv.FormatFloat(stat[1], 'f', -1, 64)}
				fmt.Println(strings.Join(s, ", "))
				total += stat[1]
			}
		}

		fmt.Println(project.Name + "," + strconv.FormatFloat(total, 'f', -1, 64))
	}

}

Question regarding adding undocumented API for retrieving org members

Hi there πŸ‘‹!

Digging through the godocs, it doesn't look like this library supports retrieving the members of an organization - which is totally fair. The api for retrieving members for an org is undocumented. As such, I know y'all are probably not open to adding support for such an endpoint (I probably wouldn't personally in an OSS project that I ran), but I thought that I might as well ask πŸ˜„.

For context, the api route is the same as the Retrieve Org endpoint, with a /members/ suffix (i.e. /api/0/organizations/{org_slug}/members/.

Cheers!

Cannot rename project with current implementation

It is impossible to use the Update project method to rename a project. Sending an object requires us to use the current slug. we can update the Name property but this one maps to the Legacy Name.

The current implementation use the slug from the object. Instead, the slug should be a separate parameter UpdateProject(o Organization, projectSlug string, p Project)

Another problem is to get the output value of the update method. For that, we should be able to pass a reference to the update method.

Current implementation:

// UpdateProject takes a organization and project then updates it on the server side
func (c *Client) UpdateProject(o Organization, p Project) error {
	return c.do("PUT", fmt.Sprintf("projects/%s/%s", *o.Slug, *p.Slug), &p, &p)
}

Suggested implementation:

// UpdateProject takes a organization and project then updates it on the server side
func (c *Client) UpdateProject(o Organization, projectSlug string, p *Project) error {
	return c.do("PUT", fmt.Sprintf("projects/%s/%s", *o.Slug, projectSlug), p, p)
}

json: cannot unmarshal bool into Go struct field Event.metadata of type string

Executing event, err := client.GetProjectEvent(org, project, eventId) returns this error:

json: cannot unmarshal bool into Go struct field Event.metadata of type string

Event metadata appears to be defined as:

Metadata *map[string]string json:"metadata,omitempty"`

Looking at the response, there can be non string data types like this boolean:

"metadata": {
  "display_title_with_tree_label": false
}

This change resolves the error:

Metadata *map[string]interface{} json:"metadata,omitempty"

make problem

Hi

When trying to compile i receive:

# github.com/atlassian/go-sentry-api
vendor/src/github.com/atlassian/go-sentry-api/client.go:60: unknown http.Client field 'Timeout' in struct literal
vendor/src/github.com/atlassian/go-sentry-api/team.go:29: undefined: http.MethodPost
vendor/src/github.com/atlassian/go-sentry-api/team.go:40: undefined: http.MethodDelete
github.com/reconquest/hierr-go
make: *** [build] Error 2

Do you know what could be a cause of this?
Thank you

Π‘annot unmarshal Issue.Metadata

A new feature display_title_with_tree_label has been added to sentry due to which issue receiving does not work now.

https://github.com/getsentry/sentry/blob/15097c5165188f1c81aa85ff643b2a3ca50a19aa/src/sentry/eventtypes/error.py#L46

Example:

{
  "metadata": {
    "value": "Maximum execution time of 420 seconds exceeded",
    "type": "ErrorException",
    "filename": "...",
    "function": "...",
    "display_title_with_tree_label": false
  }
}

An error occurs during decoding:

json: cannot unmarshal bool into Go struct field Issue.metadata of type string

https://github.com/atlassian/go-sentry-api/blob/master/issue.go#L99

Pagination code no longer seems to work.

The pagination code assumes a relative URL for the Next/Previous links

// GetPage will fetch a page via the Link object and decode it from out.
// Should be used like `client.GetPage(link.Previous, make([]Organization, 0))`
func (c *Client) GetPage(p Page, out interface{}) (*Link, error) {
	return c.rawWithPagination("GET", strings.TrimPrefix(p.URL, c.Endpoint), out, nil)
}

It prepends the Endpoint URL to the link URL. This worked until recently as Sentry .io API now returns full URLs for the link.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.