88 "strconv"
99 "strings"
1010
11+ "go.opentelemetry.io/otel/attribute"
12+ "go.opentelemetry.io/otel/trace"
13+
1114 model "github.com/ctreminiom/go-atlassian/v2/pkg/infra/models"
1215 "github.com/ctreminiom/go-atlassian/v2/service"
1316 "github.com/ctreminiom/go-atlassian/v2/service/jira"
@@ -25,10 +28,23 @@ type CommentRichTextService struct {
2528//
2629// https://docs.go-atlassian.io/jira-software-cloud/issues/comments#delete-comment
2730func (c * CommentRichTextService ) Delete (ctx context.Context , issueKeyOrID , commentID string ) (* model.ResponseScheme , error ) {
28- ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Delete" )
31+ ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Delete" , spanWithKind ( trace . SpanKindClient ) )
2932 defer span .End ()
3033
31- return c .internalClient .Delete (ctx , issueKeyOrID , commentID )
34+ addAttributes (span ,
35+ attribute .String ("operation.name" , "delete_comment" ),
36+ attribute .String ("jira.issue.key" , issueKeyOrID ),
37+ attribute .String ("jira.comment.id" , commentID ),
38+ )
39+
40+ response , err := c .internalClient .Delete (ctx , issueKeyOrID , commentID )
41+ if err != nil {
42+ recordError (span , err )
43+ return response , err
44+ }
45+
46+ setOK (span )
47+ return response , nil
3248}
3349
3450// Gets returns all comments for an issue.
@@ -37,10 +53,26 @@ func (c *CommentRichTextService) Delete(ctx context.Context, issueKeyOrID, comme
3753//
3854// https://docs.go-atlassian.io/jira-software-cloud/issues/comments#get-comments
3955func (c * CommentRichTextService ) Gets (ctx context.Context , issueKeyOrID , orderBy string , expand []string , startAt , maxResults int ) (* model.IssueCommentPageSchemeV2 , * model.ResponseScheme , error ) {
40- ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Gets" )
56+ ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Gets" , spanWithKind ( trace . SpanKindClient ) )
4157 defer span .End ()
4258
43- return c .internalClient .Gets (ctx , issueKeyOrID , orderBy , expand , startAt , maxResults )
59+ addAttributes (span ,
60+ attribute .String ("operation.name" , "get_comments" ),
61+ attribute .String ("jira.issue.key" , issueKeyOrID ),
62+ attribute .String ("jira.order_by" , orderBy ),
63+ attribute .StringSlice ("jira.expand" , expand ),
64+ attribute .Int ("jira.pagination.start_at" , startAt ),
65+ attribute .Int ("jira.pagination.max_results" , maxResults ),
66+ )
67+
68+ result , response , err := c .internalClient .Gets (ctx , issueKeyOrID , orderBy , expand , startAt , maxResults )
69+ if err != nil {
70+ recordError (span , err )
71+ return nil , response , err
72+ }
73+
74+ setOK (span )
75+ return result , response , nil
4476}
4577
4678// Get returns a comment.
@@ -49,10 +81,23 @@ func (c *CommentRichTextService) Gets(ctx context.Context, issueKeyOrID, orderBy
4981//
5082// TODO: The documentation needs to be created, raise a ticket here: https://github.com/ctreminiom/go-atlassian/issues
5183func (c * CommentRichTextService ) Get (ctx context.Context , issueKeyOrID , commentID string ) (* model.IssueCommentSchemeV2 , * model.ResponseScheme , error ) {
52- ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Get" )
84+ ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Get" , spanWithKind ( trace . SpanKindClient ) )
5385 defer span .End ()
5486
55- return c .internalClient .Get (ctx , issueKeyOrID , commentID )
87+ addAttributes (span ,
88+ attribute .String ("operation.name" , "get_comment" ),
89+ attribute .String ("jira.issue.key" , issueKeyOrID ),
90+ attribute .String ("jira.comment.id" , commentID ),
91+ )
92+
93+ result , response , err := c .internalClient .Get (ctx , issueKeyOrID , commentID )
94+ if err != nil {
95+ recordError (span , err )
96+ return nil , response , err
97+ }
98+
99+ setOK (span )
100+ return result , response , nil
56101}
57102
58103// Add adds a comment to an issue.
@@ -61,10 +106,23 @@ func (c *CommentRichTextService) Get(ctx context.Context, issueKeyOrID, commentI
61106//
62107// https://docs.go-atlassian.io/jira-software-cloud/issues/comments#add-comment
63108func (c * CommentRichTextService ) Add (ctx context.Context , issueKeyOrID string , payload * model.CommentPayloadSchemeV2 , expand []string ) (* model.IssueCommentSchemeV2 , * model.ResponseScheme , error ) {
64- ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Add" )
109+ ctx , span := tracer ().Start (ctx , "(*CommentRichTextService).Add" , spanWithKind ( trace . SpanKindClient ) )
65110 defer span .End ()
66111
67- return c .internalClient .Add (ctx , issueKeyOrID , payload , expand )
112+ addAttributes (span ,
113+ attribute .String ("operation.name" , "add_comment" ),
114+ attribute .String ("jira.issue.key" , issueKeyOrID ),
115+ attribute .StringSlice ("jira.expand" , expand ),
116+ )
117+
118+ result , response , err := c .internalClient .Add (ctx , issueKeyOrID , payload , expand )
119+ if err != nil {
120+ recordError (span , err )
121+ return nil , response , err
122+ }
123+
124+ setOK (span )
125+ return result , response , nil
68126}
69127
70128type internalRichTextCommentImpl struct {
@@ -73,33 +131,64 @@ type internalRichTextCommentImpl struct {
73131}
74132
75133func (i * internalRichTextCommentImpl ) Delete (ctx context.Context , issueKeyOrID , commentID string ) (* model.ResponseScheme , error ) {
76- ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Delete" )
134+ ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Delete" , spanWithKind ( trace . SpanKindClient ) )
77135 defer span .End ()
78136
137+ addAttributes (span ,
138+ attribute .String ("operation.name" , "delete_comment" ),
139+ attribute .String ("jira.issue.key" , issueKeyOrID ),
140+ attribute .String ("jira.comment.id" , commentID ),
141+ attribute .String ("api.version" , i .version ),
142+ )
143+
79144 if issueKeyOrID == "" {
80- return nil , fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
145+ err := fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
146+ recordError (span , err )
147+ return nil , err
81148 }
82149
83150 if commentID == "" {
84- return nil , fmt .Errorf ("jira: %w" , model .ErrNoCommentID )
151+ err := fmt .Errorf ("jira: %w" , model .ErrNoCommentID )
152+ recordError (span , err )
153+ return nil , err
85154 }
86155
87156 endpoint := fmt .Sprintf ("rest/api/%v/issue/%v/comment/%v" , i .version , issueKeyOrID , commentID )
88157
89158 request , err := i .c .NewRequest (ctx , http .MethodDelete , endpoint , "" , nil )
90159 if err != nil {
160+ recordError (span , err )
91161 return nil , err
92162 }
93163
94- return i .c .Call (request , nil )
164+ response , err := i .c .Call (request , nil )
165+ if err != nil {
166+ recordError (span , err )
167+ return response , err
168+ }
169+
170+ setOK (span )
171+ return response , nil
95172}
96173
97174func (i * internalRichTextCommentImpl ) Gets (ctx context.Context , issueKeyOrID , orderBy string , expand []string , startAt , maxResults int ) (* model.IssueCommentPageSchemeV2 , * model.ResponseScheme , error ) {
98- ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Gets" )
175+ ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Gets" , spanWithKind ( trace . SpanKindClient ) )
99176 defer span .End ()
100177
178+ addAttributes (span ,
179+ attribute .String ("operation.name" , "get_comments" ),
180+ attribute .String ("jira.issue.key" , issueKeyOrID ),
181+ attribute .String ("jira.order_by" , orderBy ),
182+ attribute .StringSlice ("jira.expand" , expand ),
183+ attribute .Int ("jira.pagination.start_at" , startAt ),
184+ attribute .Int ("jira.pagination.max_results" , maxResults ),
185+ attribute .String ("api.version" , i .version ),
186+ )
187+
101188 if issueKeyOrID == "" {
102- return nil , nil , fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
189+ err := fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
190+ recordError (span , err )
191+ return nil , nil , err
103192 }
104193
105194 params := url.Values {}
@@ -118,52 +207,78 @@ func (i *internalRichTextCommentImpl) Gets(ctx context.Context, issueKeyOrID, or
118207
119208 request , err := i .c .NewRequest (ctx , http .MethodGet , endpoint , "" , nil )
120209 if err != nil {
210+ recordError (span , err )
121211 return nil , nil , err
122212 }
123213
124214 comments := new (model.IssueCommentPageSchemeV2 )
125215 response , err := i .c .Call (request , comments )
126216 if err != nil {
217+ recordError (span , err )
127218 return nil , response , err
128219 }
129220
221+ setOK (span )
130222 return comments , response , nil
131223}
132224
133225func (i * internalRichTextCommentImpl ) Get (ctx context.Context , issueKeyOrID , commentID string ) (* model.IssueCommentSchemeV2 , * model.ResponseScheme , error ) {
134- ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Get" )
226+ ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Get" , spanWithKind ( trace . SpanKindClient ) )
135227 defer span .End ()
136228
229+ addAttributes (span ,
230+ attribute .String ("operation.name" , "get_comment" ),
231+ attribute .String ("jira.issue.key" , issueKeyOrID ),
232+ attribute .String ("jira.comment.id" , commentID ),
233+ attribute .String ("api.version" , i .version ),
234+ )
235+
137236 if issueKeyOrID == "" {
138- return nil , nil , fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
237+ err := fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
238+ recordError (span , err )
239+ return nil , nil , err
139240 }
140241
141242 if commentID == "" {
142- return nil , nil , fmt .Errorf ("jira: %w" , model .ErrNoCommentID )
243+ err := fmt .Errorf ("jira: %w" , model .ErrNoCommentID )
244+ recordError (span , err )
245+ return nil , nil , err
143246 }
144247
145248 endpoint := fmt .Sprintf ("rest/api/%v/issue/%v/comment/%v" , i .version , issueKeyOrID , commentID )
146249
147250 request , err := i .c .NewRequest (ctx , http .MethodGet , endpoint , "" , nil )
148251 if err != nil {
252+ recordError (span , err )
149253 return nil , nil , err
150254 }
151255
152256 comment := new (model.IssueCommentSchemeV2 )
153257 response , err := i .c .Call (request , comment )
154258 if err != nil {
259+ recordError (span , err )
155260 return nil , response , err
156261 }
157262
263+ setOK (span )
158264 return comment , response , nil
159265}
160266
161267func (i * internalRichTextCommentImpl ) Add (ctx context.Context , issueKeyOrID string , payload * model.CommentPayloadSchemeV2 , expand []string ) (* model.IssueCommentSchemeV2 , * model.ResponseScheme , error ) {
162- ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Add" )
268+ ctx , span := tracer ().Start (ctx , "(*internalRichTextCommentImpl).Add" , spanWithKind ( trace . SpanKindClient ) )
163269 defer span .End ()
164270
271+ addAttributes (span ,
272+ attribute .String ("operation.name" , "add_comment" ),
273+ attribute .String ("jira.issue.key" , issueKeyOrID ),
274+ attribute .StringSlice ("jira.expand" , expand ),
275+ attribute .String ("api.version" , i .version ),
276+ )
277+
165278 if issueKeyOrID == "" {
166- return nil , nil , fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
279+ err := fmt .Errorf ("jira: %w" , model .ErrNoIssueKeyOrID )
280+ recordError (span , err )
281+ return nil , nil , err
167282 }
168283
169284 params := url.Values {}
@@ -180,14 +295,17 @@ func (i *internalRichTextCommentImpl) Add(ctx context.Context, issueKeyOrID stri
180295
181296 request , err := i .c .NewRequest (ctx , http .MethodPost , endpoint .String (), "" , payload )
182297 if err != nil {
298+ recordError (span , err )
183299 return nil , nil , err
184300 }
185301
186302 comment := new (model.IssueCommentSchemeV2 )
187303 response , err := i .c .Call (request , comment )
188304 if err != nil {
305+ recordError (span , err )
189306 return nil , response , err
190307 }
191308
309+ setOK (span )
192310 return comment , response , nil
193311}
0 commit comments