Skip to content

Commit 0095c47

Browse files
authored
Skip complicated rewrites, record groups. (#104)
* Set the github repository as a group * Set the $app_name with the github action project * features: prefix with $feature/, which previously was done by IDS * Send a batch of events directly to /events/batch, without the server-side munging * Store an $anon_distinct_id in the correlation, where we used to use the repository's anon hash as the distinct ID. That was bad modeling. * Replace the correlation data with what we actually want It used to expect server-side munging, but that caused a ton of problems. This unifies that behavior. * Add /action to the app name to distinguish
1 parent 5084fa8 commit 0095c47

File tree

7 files changed

+167
-130
lines changed

7 files changed

+167
-130
lines changed

dist/index.d.ts

Lines changed: 12 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 65 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/correlation.ts

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as actionsCore from "@actions/core";
2-
import { createHash } from "node:crypto";
2+
import { createHash, randomUUID } from "node:crypto";
33

44
const OPTIONAL_VARIABLES = ["INVOCATION_ID"];
55

@@ -8,36 +8,56 @@ const OPTIONAL_VARIABLES = ["INVOCATION_ID"];
88
* JSON sent to server.
99
*/
1010
export type AnonymizedCorrelationHashes = {
11+
$anon_distinct_id: string;
12+
$groups: Record<string, string | undefined>;
13+
$session_id?: string;
1114
correlation_source: string;
12-
repository?: string;
13-
run?: string;
14-
run_differentiator?: string;
15-
workflow?: string;
16-
job?: string;
17-
groups: Record<string, string | undefined>;
15+
github_repository_hash?: string;
16+
github_workflow_hash?: string;
17+
github_workflow_job_hash?: string;
18+
github_workflow_run_differentiator_hash?: string;
19+
github_workflow_run_hash?: string;
1820
is_ci: boolean;
1921
};
2022

21-
export function identify(projectName: string): AnonymizedCorrelationHashes {
23+
export function identify(): AnonymizedCorrelationHashes {
24+
const repository = hashEnvironmentVariables("GHR", [
25+
"GITHUB_SERVER_URL",
26+
"GITHUB_REPOSITORY_OWNER",
27+
"GITHUB_REPOSITORY_OWNER_ID",
28+
"GITHUB_REPOSITORY",
29+
"GITHUB_REPOSITORY_ID",
30+
]);
31+
32+
const run_differentiator = hashEnvironmentVariables("GHWJA", [
33+
"GITHUB_SERVER_URL",
34+
"GITHUB_REPOSITORY_OWNER",
35+
"GITHUB_REPOSITORY_OWNER_ID",
36+
"GITHUB_REPOSITORY",
37+
"GITHUB_REPOSITORY_ID",
38+
"GITHUB_WORKFLOW",
39+
"GITHUB_JOB",
40+
"GITHUB_RUN_ID",
41+
"GITHUB_RUN_NUMBER",
42+
"GITHUB_RUN_ATTEMPT",
43+
"INVOCATION_ID",
44+
]);
45+
2246
const ident: AnonymizedCorrelationHashes = {
47+
$anon_distinct_id: process.env["RUNNER_TRACKING_ID"] || randomUUID(),
48+
2349
correlation_source: "github-actions",
2450

25-
repository: hashEnvironmentVariables("GHR", [
26-
"GITHUB_SERVER_URL",
27-
"GITHUB_REPOSITORY_OWNER",
28-
"GITHUB_REPOSITORY_OWNER_ID",
29-
"GITHUB_REPOSITORY",
30-
"GITHUB_REPOSITORY_ID",
31-
]),
32-
workflow: hashEnvironmentVariables("GHW", [
51+
github_repository_hash: repository,
52+
github_workflow_hash: hashEnvironmentVariables("GHW", [
3353
"GITHUB_SERVER_URL",
3454
"GITHUB_REPOSITORY_OWNER",
3555
"GITHUB_REPOSITORY_OWNER_ID",
3656
"GITHUB_REPOSITORY",
3757
"GITHUB_REPOSITORY_ID",
3858
"GITHUB_WORKFLOW",
3959
]),
40-
job: hashEnvironmentVariables("GHWJ", [
60+
github_workflow_job_hash: hashEnvironmentVariables("GHWJ", [
4161
"GITHUB_SERVER_URL",
4262
"GITHUB_REPOSITORY_OWNER",
4363
"GITHUB_REPOSITORY_OWNER_ID",
@@ -46,17 +66,7 @@ export function identify(projectName: string): AnonymizedCorrelationHashes {
4666
"GITHUB_WORKFLOW",
4767
"GITHUB_JOB",
4868
]),
49-
run: hashEnvironmentVariables("GHWJR", [
50-
"GITHUB_SERVER_URL",
51-
"GITHUB_REPOSITORY_OWNER",
52-
"GITHUB_REPOSITORY_OWNER_ID",
53-
"GITHUB_REPOSITORY",
54-
"GITHUB_REPOSITORY_ID",
55-
"GITHUB_WORKFLOW",
56-
"GITHUB_JOB",
57-
"GITHUB_RUN_ID",
58-
]),
59-
run_differentiator: hashEnvironmentVariables("GHWJA", [
69+
github_workflow_run_hash: hashEnvironmentVariables("GHWJR", [
6070
"GITHUB_SERVER_URL",
6171
"GITHUB_REPOSITORY_OWNER",
6272
"GITHUB_REPOSITORY_OWNER_ID",
@@ -65,13 +75,11 @@ export function identify(projectName: string): AnonymizedCorrelationHashes {
6575
"GITHUB_WORKFLOW",
6676
"GITHUB_JOB",
6777
"GITHUB_RUN_ID",
68-
"GITHUB_RUN_NUMBER",
69-
"GITHUB_RUN_ATTEMPT",
70-
"INVOCATION_ID",
7178
]),
72-
groups: {
73-
ci: "github-actions",
74-
project: projectName,
79+
github_workflow_run_differentiator_hash: run_differentiator,
80+
$session_id: run_differentiator,
81+
$groups: {
82+
github_repository: repository,
7583
github_organization: hashEnvironmentVariables("GHO", [
7684
"GITHUB_SERVER_URL",
7785
"GITHUB_REPOSITORY_OWNER",

0 commit comments

Comments
 (0)