Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Validate tag name format
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
if [[ ! "${{ inputs.tag_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid tag name format. Must be in the form v1.2.3"
exit 1
fi
Expand Down
1 change: 0 additions & 1 deletion acceptance/testdata/skills/skills-install.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ grep 'github-repo' $WORK/custom-skills/git-commit/SKILL.md

# Telemetry: skill_install event records agent hosts, repo identifiers,
# and (for a public repo) the installed skill name.
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100
exec gh skill install github/awesome-copilot git-commit --scope user --force --agent github-copilot
Expand Down
1 change: 0 additions & 1 deletion acceptance/testdata/skills/skills-preview.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ stderr 'not found'

# Telemetry: skill_preview event records repo identifiers and, for a
# public repo, the skill name.
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100
exec gh skill preview github/awesome-copilot git-commit
Expand Down
1 change: 0 additions & 1 deletion acceptance/testdata/telemetry/command-invocation.txtar
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Telemetry log mode outputs command invocation event to stderr
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100

Expand Down
1 change: 0 additions & 1 deletion acceptance/testdata/telemetry/no-telemetry-for-alias.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# resolved inner command should still record normally — its path is a core
# gh command and conveys no user-authored identifier.

env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The completion command should not generate a telemetry event
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# organization or project name).
[!exec:bash] skip

env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# GHES users should not get telemetry even when telemetry is enabled
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100
env GH_ENTERPRISE_TOKEN=fake-enterprise-token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The send-telemetry command should not itself generate a telemetry event
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100
env GH_TELEMETRY_ENDPOINT_URL=http://localhost:1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Command completes successfully even when telemetry endpoint is unreachable
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=enabled
env GH_TELEMETRY_SAMPLE_RATE=100
env GH_TELEMETRY_ENDPOINT_URL=http://localhost:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# names come from a fixed, hard-coded registry and do not contain any
# user-authored identifiers.

env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100

Expand Down
2 changes: 1 addition & 1 deletion internal/ghcmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Main() exitCode {
telemetryService = &telemetry.NoOpService{}
default:
telemetryState := telemetry.ParseTelemetryState(cfg.Telemetry().Value)
telemetryDisabled := os.Getenv("GH_PRIVATE_ENABLE_TELEMETRY") == "" || mightBeGHESUser(cfg)
telemetryDisabled := mightBeGHESUser(cfg)

switch telemetryState {
case telemetry.Disabled:
Expand Down
2 changes: 2 additions & 0 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -283,6 +284,7 @@ func (s *service) SetSampleRate(rate int) {
defer s.mu.Unlock()

s.sampleRate = rate
s.commonDimensions["sample_rate"] = strconv.Itoa(rate)
}

func (s *service) Flush() {
Expand Down
18 changes: 18 additions & 0 deletions internal/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,24 @@ func TestServiceSampling(t *testing.T) {
assert.False(t, called, "flusher should not be called after SetSampleRate reduced the rate")
})

t.Run("SetSampleRate updates sample_rate dimension", func(t *testing.T) {
t.Cleanup(stubDeviceID("test-device"))

var captured SendTelemetryPayload
svc := newService(func(p SendTelemetryPayload) { captured = p }, ghtelemetry.Dimensions{
"sample_rate": "1",
})
svc.sampleRate = 1
svc.sampleBucket = 0

svc.SetSampleRate(100)
svc.Record(ghtelemetry.Event{Type: "test"})
svc.Flush()

require.Len(t, captured.Events, 1)
assert.Equal(t, "100", captured.Events[0].Dimensions["sample_rate"])
})

t.Run("WithSampleRate option sets rate on construction", func(t *testing.T) {
t.Cleanup(stubDeviceID("test-device"))

Expand Down
Loading