-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add observability interfaces [IDE-175] (#3)
- Loading branch information
1 parent
6ecdd7a
commit 810feaf
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package observability | ||
|
||
import "time" | ||
|
||
// Analytics exposes different metric tracking functions. | ||
type Analytics interface { | ||
TrackScan(bool, ScanMetrics) | ||
} | ||
|
||
// ScanMetrics contains various metrics about the Snyk Code scan. | ||
type ScanMetrics struct { | ||
lastScanStartTime time.Time | ||
lastScanFileCount int | ||
} | ||
|
||
// NewScanMetrics is used to create a ScanMetrics object. | ||
func NewScanMetrics(lastScanStartTime time.Time, lastScanFileCount int) ScanMetrics { | ||
return ScanMetrics{ | ||
lastScanStartTime: lastScanStartTime, | ||
lastScanFileCount: lastScanFileCount, | ||
} | ||
} | ||
|
||
// GetDuration computes the duration since the last time a scan starter. | ||
func (s ScanMetrics) GetDuration() time.Duration { | ||
return time.Since(s.lastScanStartTime) | ||
} | ||
|
||
// GetLastScanFileCount returns the count of files since the last scan. | ||
func (s ScanMetrics) GetLastScanFileCount() int { | ||
return s.lastScanFileCount | ||
} | ||
|
||
// SetLastScanFileCount sets the count of files since the last scan. | ||
func (s *ScanMetrics) SetLastScanFileCount(lastScanFileCount int) { | ||
s.lastScanFileCount = lastScanFileCount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package observability | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// Instrumentor exposes functions used for adding instrumentation context to functions. | ||
type Instrumentor interface { | ||
StartSpan(ctx context.Context, operation string) Span | ||
NewTransaction( | ||
ctx context.Context, | ||
txName string, | ||
operation string, | ||
) Span | ||
Finish(span Span) | ||
} | ||
|
||
// Span exposes functions that have context about functions. | ||
type Span interface { | ||
SetTransactionName(name string) | ||
StartSpan(ctx context.Context) | ||
Finish() | ||
GetOperation() string | ||
GetTxName() string | ||
|
||
// GetTraceId Returns UUID of the trace | ||
GetTraceId() string | ||
Context() context.Context | ||
|
||
GetDurationMs() int64 | ||
} |