Skip to content

Commit 8891b74

Browse files
fankclaude
andcommitted
Implement comprehensive OpenTelemetry tracing for 21 jira/internal files
- Added OpenTelemetry imports and proper span creation with trace.SpanKindClient - Implemented comprehensive attributes for operation tracking, resource IDs, and pagination - Added proper error handling with recordError() and success tracking with setOK() - Updated files: comment_impl_rich_text.go, dashboard_impl.go, field_configuration_impl.go, field_configuration_item_impl.go, field_context_impl.go (24 functions), filter_impl.go (16 functions), issue_impl.go, notification_scheme_impl.go (16 functions), project_impl.go (20 functions), project_version_impl.go (16 functions), type_scheme_impl.go (20 functions), type_screen_scheme_impl.go (22 functions), workflow_impl.go (18 functions), workflow_scheme_impl.go (14 functions), workflow_status_impl.go (14 functions) - Total: 300+ functions now instrumented with comprehensive OpenTelemetry tracing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 73f6851 commit 8891b74

16 files changed

Lines changed: 2404 additions & 379 deletions

OTEL_UPDATE_GUIDE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ return result, response, nil
5555
3. ✅ attachment_impl.go
5656
4. ✅ audit_impl.go
5757
5. ✅ issue_impl_adf.go (example provided)
58+
6. ✅ comment_impl_adf.go
59+
7. ✅ comment_impl_rich_text.go
60+
8. ✅ dashboard_impl.go
61+
9. ✅ field_configuration_impl.go
62+
10. ✅ field_configuration_item_impl.go
63+
11. ✅ field_context_impl.go (24 functions)
64+
12. ✅ filter_impl.go (16 functions)
65+
13. ✅ project_impl.go (20 functions)
66+
14. ✅ issue_impl.go (utility functions)
67+
15. ✅ project_version_impl.go (16 functions)
68+
16. ✅ notification_scheme_impl.go (16 functions)
69+
17. ✅ type_scheme_impl.go (20 functions)
70+
18. ✅ type_screen_scheme_impl.go (22 functions)
71+
19. ✅ workflow_impl.go (18 functions)
72+
20. ✅ workflow_scheme_impl.go (14 functions)
73+
21. ✅ workflow_status_impl.go (14 functions)
5874

5975
### Remaining Files (58):
6076
- authentication_impl.go (no tracer calls - skip)

jira/internal/comment_impl_rich_text.go

Lines changed: 137 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
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
2730
func (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
3955
func (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
5183
func (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
63108
func (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

70128
type internalRichTextCommentImpl struct {
@@ -73,33 +131,64 @@ type internalRichTextCommentImpl struct {
73131
}
74132

75133
func (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

97174
func (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

133225
func (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

161267
func (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

Comments
 (0)