-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Telemetry header #208
Draft
nicklasl
wants to merge
6
commits into
main
Choose a base branch
from
telemetry-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9b7879
build: bump ts-proto to 2.3.0
nicklasl cc19f25
build: proto outputEncodeMethods=true
nicklasl ed4f281
feat: wip add telemetry data to header
nicklasl 7892603
fix: wip telemetry singleton
nicklasl 44f1a01
refactor: use registerCounter approach
nicklasl 02faad3
fixup! refactor: use registerCounter approach
nicklasl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
34 changes: 34 additions & 0 deletions
34
packages/sdk/proto/confidence/telemetry/v1/telemetry.proto
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,34 @@ | ||
syntax = "proto3"; | ||
|
||
package confidence.telemetry.v1; | ||
|
||
message Monitoring { | ||
repeated LibraryTraces library_traces = 1; | ||
} | ||
|
||
message LibraryTraces { | ||
Library library = 1; | ||
string library_version = 2; | ||
repeated Trace traces = 3; | ||
|
||
message Trace { | ||
TraceId id = 1; | ||
// only used for timed events. | ||
optional uint64 millisecond_duration = 2; | ||
} | ||
|
||
enum Library { | ||
LIBRARY_UNSPECIFIED = 0; | ||
LIBRARY_CONFIDENCE = 1; | ||
LIBRARY_OPEN_FEATURE = 2; | ||
LIBRARY_REACT = 3; | ||
} | ||
|
||
enum TraceId { | ||
TRACE_ID_UNSPECIFIED = 0; | ||
TRACE_ID_RESOLVE_LATENCY = 1; | ||
TRACE_ID_STALE_FLAG = 2; | ||
TRACE_ID_FLAG_TYPE_MISMATCH = 3; | ||
TRACE_ID_WITH_CONTEXT = 4; | ||
} | ||
} |
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
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
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
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,87 @@ | ||
import { | ||
LibraryTraces_Library, | ||
LibraryTraces_TraceId, | ||
Monitoring, | ||
} from './generated/confidence/telemetry/v1/telemetry'; | ||
|
||
export type TelemetryOptions = { disabled: boolean }; | ||
|
||
export type Tag = { | ||
library: LibraryTraces_Library; | ||
version: string; | ||
id: LibraryTraces_TraceId; | ||
}; | ||
|
||
export type Counter = () => void; | ||
export type Meter = (value: number) => void; | ||
|
||
export class Telemetry { | ||
private disabled: boolean; | ||
constructor(opts: TelemetryOptions) { | ||
this.disabled = opts.disabled; | ||
} | ||
|
||
private monitoring: Monitoring = { | ||
libraryTraces: [], | ||
}; | ||
|
||
private pushTrace(tags: Tag, value: number | undefined = undefined): void { | ||
const library = tags.library; | ||
const version = tags.version; | ||
const existing = this.monitoring.libraryTraces.find(trace => { | ||
return trace.library === library && trace.libraryVersion === version; | ||
}); | ||
if (existing) { | ||
existing.traces.push({ | ||
id: tags.id, | ||
millisecondDuration: value, | ||
}); | ||
} else { | ||
// should never happen. remove? | ||
this.monitoring.libraryTraces.push({ | ||
library, | ||
libraryVersion: version, | ||
traces: [ | ||
{ | ||
id: tags.id, | ||
millisecondDuration: value, | ||
}, | ||
], | ||
}); | ||
} | ||
} | ||
|
||
registerCounter(tag: Tag): Counter { | ||
this.monitoring.libraryTraces.push({ | ||
library: tag.library, | ||
libraryVersion: tag.version, | ||
traces: [], | ||
}); | ||
return () => { | ||
this.pushTrace(tag); | ||
}; | ||
} | ||
|
||
registerMeter(tag: Tag): Meter { | ||
this.monitoring.libraryTraces.push({ | ||
library: tag.library, | ||
libraryVersion: tag.version, | ||
traces: [], | ||
}); | ||
return (value: number) => { | ||
this.pushTrace(tag, value); | ||
}; | ||
} | ||
|
||
getSnapshot(): Monitoring | undefined { | ||
if (this.disabled) { | ||
return undefined; | ||
} | ||
const snapshot = { ...this.monitoring }; | ||
this.monitoring.libraryTraces.forEach(trace => { | ||
// only clear traces. keep library and version since they are registered. | ||
trace.traces = []; | ||
}); | ||
return snapshot; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, combined with how the interceptor treats it, decided wether or not we add the telemetry header.