Skip to content

Commit

Permalink
feat: add observability interfaces [IDE-175] (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Mar 13, 2024
1 parent 6ecdd7a commit 810feaf
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
37 changes: 37 additions & 0 deletions observability/analytics.go
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
}
31 changes: 31 additions & 0 deletions observability/instrumentor.go
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
}

0 comments on commit 810feaf

Please sign in to comment.