Repository navigation
Expand file tree
/
Copy pathlog.go
More file actions
323 lines (300 loc) · 12.1 KB
/
Copy pathlog.go
File metadata and controls
323 lines (300 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package contextdev
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/context-dot-dev/context-go-sdk/v2/internal/apijson"
"github.com/context-dot-dev/context-go-sdk/v2/internal/apiquery"
"github.com/context-dot-dev/context-go-sdk/v2/internal/requestconfig"
"github.com/context-dot-dev/context-go-sdk/v2/option"
"github.com/context-dot-dev/context-go-sdk/v2/packages/param"
"github.com/context-dot-dev/context-go-sdk/v2/packages/respjson"
)
// Read your organization's API request logs.
//
// LogService contains methods and other services that help with interacting with
// the context.dev API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewLogService] method instead.
type LogService struct {
options []option.RequestOption
}
// NewLogService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewLogService(opts ...option.RequestOption) (r LogService) {
r = LogService{}
r.options = opts
return
}
// Retrieve a request’s metadata, retained input, and response.
func (r *LogService) Get(ctx context.Context, requestID string, opts ...option.RequestOption) (res *LogGetResponse, err error) {
opts = slices.Concat(r.options, opts)
if requestID == "" {
err = errors.New("missing required request_id parameter")
return nil, err
}
path := fmt.Sprintf("org/logs/%s", requestID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// List your organization’s request logs with filters and pagination. Logs also
// include batch settlements and monitor runs.
func (r *LogService) List(ctx context.Context, query LogListParams, opts ...option.RequestOption) (res *LogListResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "org/logs"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
type LogGetResponse struct {
Data LogGetResponseData `json:"data" api:"required"`
// Unique ID of this request, also in `X-Request-Id`. Include it when contacting
// support.
RequestID string `json:"request_id" api:"required" format:"uuid"`
// Credits this request used and your remaining balance.
KeyMetadata LogGetResponseKeyMetadata `json:"key_metadata"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
RequestID respjson.Field
KeyMetadata respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogGetResponse) RawJSON() string { return r.JSON.raw }
func (r *LogGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type LogGetResponseData struct {
// Credits charged for this request.
CreditsUsed int64 `json:"credits_used" api:"required"`
// The `error_code` from the response, or null on success.
ErrorCode string `json:"error_code" api:"required"`
// What was sent with the request.
Input LogGetResponseDataInput `json:"input" api:"required"`
// ID of the API key that made the request.
KeyID string `json:"key_id" api:"required"`
// Server-side processing time in milliseconds.
LatencyMs float64 `json:"latency_ms" api:"required"`
// HTTP method, or `MONITOR` / `BATCH` for monitor-run and batch-settlement
// entries.
Method string `json:"method" api:"required"`
// Endpoint path as called.
Path string `json:"path" api:"required"`
// Request ID of the logged API call.
RequestID string `json:"request_id" api:"required"`
// HTTP status code returned.
StatusCode int64 `json:"status_code" api:"required"`
// Request tags supplied by the caller.
Tags []string `json:"tags" api:"required"`
// When the request completed.
Timestamp time.Time `json:"timestamp" api:"required" format:"date-time"`
// User-Agent header of the request.
UserAgent string `json:"user_agent" api:"required"`
// Whether the request was made under zero data retention.
Zdr bool `json:"zdr" api:"required"`
// The retained JSON response with credentials redacted, or null when unavailable.
Response any `json:"response"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsUsed respjson.Field
ErrorCode respjson.Field
Input respjson.Field
KeyID respjson.Field
LatencyMs respjson.Field
Method respjson.Field
Path respjson.Field
RequestID respjson.Field
StatusCode respjson.Field
Tags respjson.Field
Timestamp respjson.Field
UserAgent respjson.Field
Zdr respjson.Field
Response respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogGetResponseData) RawJSON() string { return r.JSON.raw }
func (r *LogGetResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// What was sent with the request.
type LogGetResponseDataInput struct {
// Query parameters as sent.
Query map[string]any `json:"query" api:"required"`
// Request body with credentials and uploaded content redacted.
Body any `json:"body"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Query respjson.Field
Body respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogGetResponseDataInput) RawJSON() string { return r.JSON.raw }
func (r *LogGetResponseDataInput) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Credits this request used and your remaining balance.
type LogGetResponseKeyMetadata struct {
// Credits charged for this request.
CreditsConsumed int64 `json:"credits_consumed" api:"required"`
// Credits remaining for your organization.
CreditsRemaining int64 `json:"credits_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsConsumed respjson.Field
CreditsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogGetResponseKeyMetadata) RawJSON() string { return r.JSON.raw }
func (r *LogGetResponseKeyMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type LogListResponse struct {
// Log entries, newest first.
Data []LogListResponseData `json:"data" api:"required"`
// Whether a next page exists.
HasMore bool `json:"has_more" api:"required"`
// Entries per page.
Limit int64 `json:"limit" api:"required"`
// Current page number.
Page int64 `json:"page" api:"required"`
// Unique ID of this request, also in `X-Request-Id`. Include it when contacting
// support.
RequestID string `json:"request_id" api:"required" format:"uuid"`
// Credits this request used and your remaining balance.
KeyMetadata LogListResponseKeyMetadata `json:"key_metadata"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
HasMore respjson.Field
Limit respjson.Field
Page respjson.Field
RequestID respjson.Field
KeyMetadata respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogListResponse) RawJSON() string { return r.JSON.raw }
func (r *LogListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type LogListResponseData struct {
// Credits charged for this request.
CreditsUsed int64 `json:"credits_used" api:"required"`
// The `error_code` from the response, or null on success.
ErrorCode string `json:"error_code" api:"required"`
// ID of the API key that made the request.
KeyID string `json:"key_id" api:"required"`
// Server-side processing time in milliseconds.
LatencyMs float64 `json:"latency_ms" api:"required"`
// HTTP method, or `MONITOR` / `BATCH` for monitor-run and batch-settlement
// entries.
Method string `json:"method" api:"required"`
// Endpoint path as called.
Path string `json:"path" api:"required"`
// Request ID of the logged API call.
RequestID string `json:"request_id" api:"required"`
// HTTP status code returned.
StatusCode int64 `json:"status_code" api:"required"`
// Request tags supplied by the caller.
Tags []string `json:"tags" api:"required"`
// When the request completed.
Timestamp time.Time `json:"timestamp" api:"required" format:"date-time"`
// Whether the request was made under zero data retention.
Zdr bool `json:"zdr" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsUsed respjson.Field
ErrorCode respjson.Field
KeyID respjson.Field
LatencyMs respjson.Field
Method respjson.Field
Path respjson.Field
RequestID respjson.Field
StatusCode respjson.Field
Tags respjson.Field
Timestamp respjson.Field
Zdr respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogListResponseData) RawJSON() string { return r.JSON.raw }
func (r *LogListResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Credits this request used and your remaining balance.
type LogListResponseKeyMetadata struct {
// Credits charged for this request.
CreditsConsumed int64 `json:"credits_consumed" api:"required"`
// Credits remaining for your organization.
CreditsRemaining int64 `json:"credits_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsConsumed respjson.Field
CreditsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LogListResponseKeyMetadata) RawJSON() string { return r.JSON.raw }
func (r *LogListResponseKeyMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type LogListParams struct {
// Filter by the `error_code` returned in the response.
ErrorCode param.Opt[string] `query:"error_code,omitzero" json:"-"`
// Only include requests that returned a 4xx or 5xx status.
ErrorsOnly param.Opt[bool] `query:"errors_only,omitzero" json:"-"`
// Only include requests at or after this ISO 8601 timestamp. Defaults to 24 hours
// before `to`.
From param.Opt[time.Time] `query:"from,omitzero" format:"date-time" json:"-"`
// Filter by the API key that made the request.
KeyID param.Opt[string] `query:"key_id,omitzero" json:"-"`
// Number of log entries per page.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Page number, starting at 1.
Page param.Opt[int64] `query:"page,omitzero" json:"-"`
// Filter by endpoint path, with or without the /v1 prefix.
Path param.Opt[string] `query:"path,omitzero" json:"-"`
// Case-insensitive substring match against the request query and body, e.g. a
// domain.
Search param.Opt[string] `query:"search,omitzero" json:"-"`
// Filter by exact HTTP status code.
StatusCode param.Opt[int64] `query:"status_code,omitzero" json:"-"`
// Comma-separated request tags. Matches requests carrying any of them. Up to 20
// tags, each 1-50 characters.
Tags param.Opt[string] `query:"tags,omitzero" json:"-"`
// Only include requests at or before this ISO 8601 timestamp. Defaults to now.
To param.Opt[time.Time] `query:"to,omitzero" format:"date-time" json:"-"`
paramObj
}
// URLQuery serializes [LogListParams]'s query parameters as `url.Values`.
func (r LogListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}