Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OpenTelemetry tracer #335

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions admin/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type Client struct {
// NewRequest creates a new HTTP request with the given context, method, URL string, content type, and body.
// It returns an HTTP request and an error.
func (c *Client) NewRequest(ctx context.Context, method, urlStr, contentType string, body interface{}) (*http.Request, error) {
ctx, span := tracer().Start(ctx, "(*Client).NewRequest")
defer span.End()

// Parse the relative URL.
rel, err := url.Parse(urlStr)
Expand Down
20 changes: 20 additions & 0 deletions admin/internal/organization_directory_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type OrganizationDirectoryService struct {
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/directory#users-last-active-dates
func (o *OrganizationDirectoryService) Activity(ctx context.Context, organizationID, accountID string) (*model.UserProductAccessScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationDirectoryService).Activity")
defer span.End()

return o.internalClient.Activity(ctx, organizationID, accountID)
}

Expand All @@ -49,6 +52,9 @@ func (o *OrganizationDirectoryService) Activity(ctx context.Context, organizatio
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/directory#remove-user-access
func (o *OrganizationDirectoryService) Remove(ctx context.Context, organizationID, accountID string) (*model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationDirectoryService).Remove")
defer span.End()

return o.internalClient.Remove(ctx, organizationID, accountID)
}

Expand All @@ -62,6 +68,9 @@ func (o *OrganizationDirectoryService) Remove(ctx context.Context, organizationI
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/directory#suspend-user-access
func (o *OrganizationDirectoryService) Suspend(ctx context.Context, organizationID, accountID string) (*model.GenericActionSuccessScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationDirectoryService).Suspend")
defer span.End()

return o.internalClient.Suspend(ctx, organizationID, accountID)
}

Expand All @@ -75,6 +84,9 @@ func (o *OrganizationDirectoryService) Suspend(ctx context.Context, organization
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/directory#restore-user-access
func (o *OrganizationDirectoryService) Restore(ctx context.Context, organizationID, accountID string) (*model.GenericActionSuccessScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationDirectoryService).Restore")
defer span.End()

return o.internalClient.Restore(ctx, organizationID, accountID)
}

Expand All @@ -83,6 +95,8 @@ type internalOrganizationDirectoryServiceImpl struct {
}

func (i *internalOrganizationDirectoryServiceImpl) Activity(ctx context.Context, organizationID, accountID string) (*model.UserProductAccessScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationDirectoryServiceImpl).Activity")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -109,6 +123,8 @@ func (i *internalOrganizationDirectoryServiceImpl) Activity(ctx context.Context,
}

func (i *internalOrganizationDirectoryServiceImpl) Remove(ctx context.Context, organizationID, accountID string) (*model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationDirectoryServiceImpl).Remove")
defer span.End()

if organizationID == "" {
return nil, model.ErrNoAdminOrganization
Expand All @@ -129,6 +145,8 @@ func (i *internalOrganizationDirectoryServiceImpl) Remove(ctx context.Context, o
}

func (i *internalOrganizationDirectoryServiceImpl) Suspend(ctx context.Context, organizationID, accountID string) (*model.GenericActionSuccessScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationDirectoryServiceImpl).Suspend")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -155,6 +173,8 @@ func (i *internalOrganizationDirectoryServiceImpl) Suspend(ctx context.Context,
}

func (i *internalOrganizationDirectoryServiceImpl) Restore(ctx context.Context, organizationID, accountID string) (*model.GenericActionSuccessScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationDirectoryServiceImpl).Restore")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand Down
40 changes: 40 additions & 0 deletions admin/internal/organization_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type OrganizationService struct {
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-organizations
func (o *OrganizationService) Gets(ctx context.Context, cursor string) (*model.AdminOrganizationPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Gets")
defer span.End()

return o.internalClient.Gets(ctx, cursor)
}

Expand All @@ -40,6 +43,9 @@ func (o *OrganizationService) Gets(ctx context.Context, cursor string) (*model.A
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-an-organization-by-id
func (o *OrganizationService) Get(ctx context.Context, organizationID string) (*model.AdminOrganizationScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Get")
defer span.End()

return o.internalClient.Get(ctx, organizationID)
}

Expand All @@ -49,6 +55,9 @@ func (o *OrganizationService) Get(ctx context.Context, organizationID string) (*
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-users-in-an-organization
func (o *OrganizationService) Users(ctx context.Context, organizationID, cursor string) (*model.OrganizationUserPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Users")
defer span.End()

return o.internalClient.Users(ctx, organizationID, cursor)
}

Expand All @@ -58,6 +67,9 @@ func (o *OrganizationService) Users(ctx context.Context, organizationID, cursor
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-domains-in-an-organization
func (o *OrganizationService) Domains(ctx context.Context, organizationID, cursor string) (*model.OrganizationDomainPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Domains")
defer span.End()

return o.internalClient.Domains(ctx, organizationID, cursor)
}

Expand All @@ -67,6 +79,9 @@ func (o *OrganizationService) Domains(ctx context.Context, organizationID, curso
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-domain-by-id
func (o *OrganizationService) Domain(ctx context.Context, organizationID, domainID string) (*model.OrganizationDomainScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Domain")
defer span.End()

return o.internalClient.Domain(ctx, organizationID, domainID)
}

Expand All @@ -76,6 +91,9 @@ func (o *OrganizationService) Domain(ctx context.Context, organizationID, domain
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-an-audit-log-of-events
func (o *OrganizationService) Events(ctx context.Context, organizationID string, options *model.OrganizationEventOptScheme, cursor string) (*model.OrganizationEventPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Events")
defer span.End()

return o.internalClient.Events(ctx, organizationID, options, cursor)
}

Expand All @@ -85,6 +103,9 @@ func (o *OrganizationService) Events(ctx context.Context, organizationID string,
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-an-event-by-id
func (o *OrganizationService) Event(ctx context.Context, organizationID, eventID string) (*model.OrganizationEventScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Event")
defer span.End()

return o.internalClient.Event(ctx, organizationID, eventID)
}

Expand All @@ -94,6 +115,9 @@ func (o *OrganizationService) Event(ctx context.Context, organizationID, eventID
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization#get-list-of-event-actions
func (o *OrganizationService) Actions(ctx context.Context, organizationID string) (*model.OrganizationEventActionScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationService).Actions")
defer span.End()

return o.internalClient.Actions(ctx, organizationID)
}

Expand All @@ -102,6 +126,8 @@ type internalOrganizationImpl struct {
}

func (i *internalOrganizationImpl) Gets(ctx context.Context, cursor string) (*model.AdminOrganizationPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Gets")
defer span.End()

var endpoint strings.Builder
endpoint.WriteString("admin/v1/orgs")
Expand All @@ -128,6 +154,8 @@ func (i *internalOrganizationImpl) Gets(ctx context.Context, cursor string) (*mo
}

func (i *internalOrganizationImpl) Get(ctx context.Context, organizationID string) (*model.AdminOrganizationScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Get")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -150,6 +178,8 @@ func (i *internalOrganizationImpl) Get(ctx context.Context, organizationID strin
}

func (i *internalOrganizationImpl) Users(ctx context.Context, organizationID, cursor string) (*model.OrganizationUserPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Users")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand Down Expand Up @@ -180,6 +210,8 @@ func (i *internalOrganizationImpl) Users(ctx context.Context, organizationID, cu
}

func (i *internalOrganizationImpl) Domains(ctx context.Context, organizationID, cursor string) (*model.OrganizationDomainPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Domains")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand Down Expand Up @@ -210,6 +242,8 @@ func (i *internalOrganizationImpl) Domains(ctx context.Context, organizationID,
}

func (i *internalOrganizationImpl) Domain(ctx context.Context, organizationID, domainID string) (*model.OrganizationDomainScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Domain")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -236,6 +270,8 @@ func (i *internalOrganizationImpl) Domain(ctx context.Context, organizationID, d
}

func (i *internalOrganizationImpl) Events(ctx context.Context, organizationID string, options *model.OrganizationEventOptScheme, cursor string) (*model.OrganizationEventPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Events")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand Down Expand Up @@ -289,6 +325,8 @@ func (i *internalOrganizationImpl) Events(ctx context.Context, organizationID st
}

func (i *internalOrganizationImpl) Event(ctx context.Context, organizationID, eventID string) (*model.OrganizationEventScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Event")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -315,6 +353,8 @@ func (i *internalOrganizationImpl) Event(ctx context.Context, organizationID, ev
}

func (i *internalOrganizationImpl) Actions(ctx context.Context, organizationID string) (*model.OrganizationEventActionScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationImpl).Actions")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand Down
25 changes: 25 additions & 0 deletions admin/internal/organization_policy_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type OrganizationPolicyService struct {
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/policy#get-list-of-policies
func (o *OrganizationPolicyService) Gets(ctx context.Context, organizationID, policyType, cursor string) (*model.OrganizationPolicyPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationPolicyService).Gets")
defer span.End()

return o.internalClient.Gets(ctx, organizationID, policyType, cursor)
}

Expand All @@ -38,6 +41,9 @@ func (o *OrganizationPolicyService) Gets(ctx context.Context, organizationID, po
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/policy#get-a-policy-by-id
func (o *OrganizationPolicyService) Get(ctx context.Context, organizationID, policyID string) (*model.OrganizationPolicyScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationPolicyService).Get")
defer span.End()

return o.internalClient.Get(ctx, organizationID, policyID)
}

Expand All @@ -47,6 +53,9 @@ func (o *OrganizationPolicyService) Get(ctx context.Context, organizationID, pol
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/policy#create-a-policy
func (o *OrganizationPolicyService) Create(ctx context.Context, organizationID string, payload *model.OrganizationPolicyData) (*model.OrganizationPolicyScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationPolicyService).Create")
defer span.End()

return o.internalClient.Create(ctx, organizationID, payload)
}

Expand All @@ -56,6 +65,9 @@ func (o *OrganizationPolicyService) Create(ctx context.Context, organizationID s
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/policy#update-a-policy
func (o *OrganizationPolicyService) Update(ctx context.Context, organizationID, policyID string, payload *model.OrganizationPolicyData) (*model.OrganizationPolicyScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationPolicyService).Update")
defer span.End()

return o.internalClient.Update(ctx, organizationID, policyID, payload)
}

Expand All @@ -65,6 +77,9 @@ func (o *OrganizationPolicyService) Update(ctx context.Context, organizationID,
//
// https://docs.go-atlassian.io/atlassian-admin-cloud/organization/policy#delete-a-policy
func (o *OrganizationPolicyService) Delete(ctx context.Context, organizationID, policyID string) (*model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*OrganizationPolicyService).Delete")
defer span.End()

return o.internalClient.Delete(ctx, organizationID, policyID)
}

Expand All @@ -73,6 +88,8 @@ type internalOrganizationPolicyImpl struct {
}

func (i *internalOrganizationPolicyImpl) Gets(ctx context.Context, organizationID, policyType, cursor string) (*model.OrganizationPolicyPageScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationPolicyImpl).Gets")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand Down Expand Up @@ -109,6 +126,8 @@ func (i *internalOrganizationPolicyImpl) Gets(ctx context.Context, organizationI
}

func (i *internalOrganizationPolicyImpl) Get(ctx context.Context, organizationID, policyID string) (*model.OrganizationPolicyScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationPolicyImpl).Get")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -135,6 +154,8 @@ func (i *internalOrganizationPolicyImpl) Get(ctx context.Context, organizationID
}

func (i *internalOrganizationPolicyImpl) Create(ctx context.Context, organizationID string, payload *model.OrganizationPolicyData) (*model.OrganizationPolicyScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationPolicyImpl).Create")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -157,6 +178,8 @@ func (i *internalOrganizationPolicyImpl) Create(ctx context.Context, organizatio
}

func (i *internalOrganizationPolicyImpl) Update(ctx context.Context, organizationID, policyID string, payload *model.OrganizationPolicyData) (*model.OrganizationPolicyScheme, *model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationPolicyImpl).Update")
defer span.End()

if organizationID == "" {
return nil, nil, model.ErrNoAdminOrganization
Expand All @@ -183,6 +206,8 @@ func (i *internalOrganizationPolicyImpl) Update(ctx context.Context, organizatio
}

func (i *internalOrganizationPolicyImpl) Delete(ctx context.Context, organizationID, policyID string) (*model.ResponseScheme, error) {
ctx, span := tracer().Start(ctx, "(*internalOrganizationPolicyImpl).Delete")
defer span.End()

if organizationID == "" {
return nil, model.ErrNoAdminOrganization
Expand Down
12 changes: 12 additions & 0 deletions admin/internal/otel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package internal

Check warning

Code scanning / Revive (reported by Codacy)

should have a package comment

should have a package comment

import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

const tracerName = "github.com/ctreminiom/go-atlassian/v2/admin/internal"

func tracer(opts ...trace.TracerOption) trace.Tracer {
return otel.Tracer(tracerName, opts...)
}
Loading
Loading