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
3 changes: 2 additions & 1 deletion allowlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"process.runtime.name": {"about": "nodejs or pharo.", "type": "string", "values": ["nodejs", "pharo"]},
"process.runtime.version": {"about": "Node's major version, or Pharo's major and minor.", "type": "string", "extract": {"plexus": "^v?([0-9]{1,4})(?:\\.[\\s\\S]*)?$", "pharo-mcp": "^v?([0-9]{1,4}\\.[0-9]{1,4})(?:[.+-][\\s\\S]*)?$"}, "pattern": "version"},
"deployment.environment.name": {"about": "field for participants, eval for our own evaluation runs, preview while previewing, check for pharo-agent-telemetry check-deployment.", "type": "string", "values": ["field", "eval", "preview", "check"]},
"pharo_agent_evals.variant": {"about": "Which variant of an evaluation run sent the span: the build under test, which may report a released version. Kept only for eval.", "type": "string", "pattern": "variant", "when": {"deployment.environment.name": "eval"}}
"pharo_agent_evals.variant": {"about": "Which variant of an evaluation run sent the span: the build under test, which may report a released version. Kept only for eval.", "type": "string", "pattern": "variant", "when": {"deployment.environment.name": "eval"}},
"pharo_agent_telemetry.filter.version": {"about": "The version of this study's filter on your machine that kept the span, which the agent sets: data kept by an older filter, before you joined again, tells itself apart.", "type": "string", "pattern": "version"}
},
"span": {
"session.id": {"about": "Groups the calls of one working session. PLexus makes it at random, or MCP when the call came without one, and either starts another after 30 minutes without a call; it is replaced by its keyed hash before it leaves your machine.", "type": "string", "pattern": "text", "hash": "session"},
Expand Down
8 changes: 7 additions & 1 deletion collector/otelcol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ processors:
trace_statements:
- context: resource
statements:
- "keep_keys(attributes, [\"service.name\", \"service.version\", \"os.type\", \"process.runtime.name\", \"process.runtime.version\", \"deployment.environment.name\", \"pharo_agent_evals.variant\"])"
- "keep_keys(attributes, [\"service.name\", \"service.version\", \"os.type\", \"process.runtime.name\", \"process.runtime.version\", \"deployment.environment.name\", \"pharo_agent_evals.variant\", \"pharo_agent_telemetry.filter.version\"])"
- "delete_key(attributes, \"service.name\") where not IsString(attributes[\"service.name\"])"
- "set(attributes[\"service.name\"], \"****\") where IsString(attributes[\"service.name\"]) and IsMatch(attributes[\"service.name\"], \"(?is)^.*(/Users/|/home/|[A-Z]:\\\\\\\\Users\\\\\\\\).*$\")"
- "set(attributes[\"service.name\"], \"****\") where IsString(attributes[\"service.name\"]) and IsMatch(attributes[\"service.name\"], \"(?s)^.*[A-Za-z0-9._%+-]@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2}.*$\")"
Expand Down Expand Up @@ -109,6 +109,12 @@ processors:
- "set(attributes[\"pharo_agent_evals.variant\"], \"****\") where IsString(attributes[\"pharo_agent_evals.variant\"]) and IsMatch(attributes[\"pharo_agent_evals.variant\"], \"(?s)^.*\\\\b(?:[0-9]{1,3}\\\\.){3}[0-9]{1,3}\\\\b.*$\")"
- "set(attributes[\"pharo_agent_evals.variant\"], \"****\") where IsString(attributes[\"pharo_agent_evals.variant\"]) and IsMatch(attributes[\"pharo_agent_evals.variant\"], \"(?is)^.*(?:::|\\\\b[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){7}\\\\b).*$\")"
- "delete_key(attributes, \"pharo_agent_evals.variant\") where IsString(attributes[\"pharo_agent_evals.variant\"]) and not IsMatch(attributes[\"pharo_agent_evals.variant\"], \"^(?:[A-Za-z0-9][A-Za-z0-9._-]{0,63})$\")"
- "delete_key(attributes, \"pharo_agent_telemetry.filter.version\") where not IsString(attributes[\"pharo_agent_telemetry.filter.version\"])"
- "set(attributes[\"pharo_agent_telemetry.filter.version\"], \"****\") where IsString(attributes[\"pharo_agent_telemetry.filter.version\"]) and IsMatch(attributes[\"pharo_agent_telemetry.filter.version\"], \"(?is)^.*(/Users/|/home/|[A-Z]:\\\\\\\\Users\\\\\\\\).*$\")"
- "set(attributes[\"pharo_agent_telemetry.filter.version\"], \"****\") where IsString(attributes[\"pharo_agent_telemetry.filter.version\"]) and IsMatch(attributes[\"pharo_agent_telemetry.filter.version\"], \"(?s)^.*[A-Za-z0-9._%+-]@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2}.*$\")"
- "set(attributes[\"pharo_agent_telemetry.filter.version\"], \"****\") where IsString(attributes[\"pharo_agent_telemetry.filter.version\"]) and IsMatch(attributes[\"pharo_agent_telemetry.filter.version\"], \"(?s)^.*\\\\b(?:[0-9]{1,3}\\\\.){3}[0-9]{1,3}\\\\b.*$\")"
- "set(attributes[\"pharo_agent_telemetry.filter.version\"], \"****\") where IsString(attributes[\"pharo_agent_telemetry.filter.version\"]) and IsMatch(attributes[\"pharo_agent_telemetry.filter.version\"], \"(?is)^.*(?:::|\\\\b[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){7}\\\\b).*$\")"
- "delete_key(attributes, \"pharo_agent_telemetry.filter.version\") where IsString(attributes[\"pharo_agent_telemetry.filter.version\"]) and not IsMatch(attributes[\"pharo_agent_telemetry.filter.version\"], \"^(?:[0-9]{1,4}(?:\\\\.[0-9]{1,4}){0,2}(?:-(?:alpha|beta|rc)(?:\\\\.[0-9]{1,4})?)?)$\")"
- "delete_key(attributes, \"pharo_agent_evals.variant\") where attributes[\"deployment.environment.name\"] != \"eval\""
- "set(schema_url, \"\")"
- "set(dropped_attributes_count, 0)"
Expand Down
1 change: 1 addition & 0 deletions docs/participants.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Where it ran:
| `process.runtime.version` | plexus, pharo-mcp | Node's major version, or Pharo's major and minor. | a version, major from plexus, major and minor from pharo-mcp |
| `deployment.environment.name` | plexus, pharo-mcp | field for participants, eval for our own evaluation runs, preview while previewing, check for pharo-agent-telemetry check-deployment. | one of `field`, `eval`, `preview`, `check` |
| `pharo_agent_evals.variant` | plexus, pharo-mcp | Which variant of an evaluation run sent the span: the build under test, which may report a released version. Kept only for eval. | a build's name, only beside `deployment.environment.name` `eval` |
| `pharo_agent_telemetry.filter.version` | plexus, pharo-mcp | The version of this study's filter on your machine that kept the span, which the agent sets: data kept by an older filter, before you joined again, tells itself apart. | a version |

What happened:

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@evref-bl/pharo-agent-study",
"version": "0.3.0",
"version": "0.4.0",
"description": "Evref-BL's study of how agents use the Pharo tools: preview, join or leave it.",
"license": "MIT",
"type": "module",
Expand All @@ -19,7 +19,7 @@
"node": ">=22.15.0"
},
"dependencies": {
"@evref-bl/pharo-agent-telemetry": "0.2.0"
"@evref-bl/pharo-agent-telemetry": "0.3.0"
},
"scripts": {
"generate": "pharo-agent-telemetry generate",
Expand Down
28 changes: 20 additions & 8 deletions telemetry-transform.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";

export const version = "0.3.0";
export const version = "0.4.0";

const allowlist = {
"$comment": "What the study keeps, and in what shape. `pharo-agent-telemetry generate` writes, from this file and catalog.json (the tools and words `pharo-agent-telemetry catalog` reads in the projects' source, and the classes MCP names an exception by in an image of each Pharo version), the filter `join` installs on a participant's machine (telemetry-transform.mjs), the collector's configuration (collector/otelcol.yaml), which applies the same rules again, and docs/participants.md; `pharo-agent-telemetry check` fails when any is out of date. A span is kept only from the services listed, with their scope, one of their span names, and the kinds and attributes a service `requires`. Every attribute not listed is dropped; a listed one is kept only from the services in `from` (both when absent), with the type given, and only when its value has the shape given (and, with `words`, is made of `vocabulary` words in that form: a name, or a JSON pointer of names), else it is dropped, or replaced by `otherwise`; a list with an element of another shape is dropped, but for `published`, whose elements not in a `published` set become `otherwise`. `extract` keeps the first group of a pattern, per service; `when` keeps a resource attribute only beside another's value; `beside` keeps an attribute only beside another that holds a value of its set, not its `otherwise`. `name` marks a name of the tool called: dropped (or replaced by `nameOther`) on a pharo-mcp span whose origin is other for a tool no project publishes, and on a plexus span unless it is for one of PLexus's own tools it did not forward. `own` marks what MCP says only of its own answer: dropped on a pharo-mcp span whose origin is other, for a tool no project publishes. `tool` marks the tool's name: kept when a project publishes it; else, on a pharo-mcp span whose origin is mcp or unknown, when it is made of vocabulary words; else `otherwise`. `grows` names the sets that grow with the projects' releases, by the shape of their members (a tool's name, a word, a code, a class): the only sets a signed catalog the agents fetch may add to.",
Expand Down Expand Up @@ -103,6 +103,11 @@ const allowlist = {
"when": {
"deployment.environment.name": "eval"
}
},
"pharo_agent_telemetry.filter.version": {
"about": "The version of this study's filter on your machine that kept the span, which the agent sets: data kept by an older filter, before you joined again, tells itself apart.",
"type": "string",
"pattern": "version"
}
},
"span": {
Expand Down Expand Up @@ -404,6 +409,9 @@ const sessionKey = "session.id";
/** The attribute the agent adds: where a span comes in its session, which times kept to the week lose. */
const offsetKey = "pharo_agent_telemetry.session.offset_ms";

/** The resource attribute the agent adds when its allowlist lists it: the version of the study's filter that kept the span. */
const filterVersionKey = "pharo_agent_telemetry.filter.version";

/**
* A name as the vocabulary check reads it: each camelCase word boundary
* (`className`, `HTTPServer`) made a `_`, in lower case. Written as the two
Expand Down Expand Up @@ -817,12 +825,15 @@ function keepSpan(rules, span, service, options) {
* hash?: (tag: string, value: string, length?: number) => string,
* report?: (problem: string) => void,
* sessionOffset?: (session: string, start: bigint) => bigint,
* filterVersion?: string,
* }} [options]
* without `hash`, ids and session ids are kept as they are, as `pharo-agent-telemetry audit` reads an archive;
* with `sessionOffset`, each span with a session gets its offset in it, as the agent adds it
* with `sessionOffset`, each span with a session gets its offset in it, as the agent adds it;
* with `filterVersion`, each resource the version of the filter, in place of any a tool sent, when the allowlist lists it
*/
function transformTraces(rules, request, options = {}) {
const settings = { hash: options.hash, report: options.report ?? (() => {}), sessionOffset: options.sessionOffset };
const stamp = typeof options.filterVersion === "string" && rules.resource.some((spec) => spec.key === filterVersionKey) ? options.filterVersion : undefined;
if (request === null || typeof request !== "object" || !Array.isArray(request.resourceSpans)) return null;
const resourceSpans = [];
for (const each of request.resourceSpans) {
Expand All @@ -837,6 +848,7 @@ function transformTraces(rules, request, options = {}) {
settings.report("resource: gives an attribute twice");
continue;
}
if (stamp !== undefined) resource.set(filterVersionKey, { type: "string", value: stamp });
const scopeSpans = [];
for (const scoped of Array.isArray(each.scopeSpans) ? each.scopeSpans : []) {
if (scoped?.scope?.name !== rules.services[service].scope) {
Expand Down Expand Up @@ -995,17 +1007,17 @@ function withCatalogSets(allowlist, catalog) {
*
* @param {any} allowlist
* @param {string | undefined} key
* @param {{ offsets?: boolean, sessions?: Map<string, { first: bigint, seen: number }>, catalog?: any }} [options] `offsets: false` leaves out the places, as the collector, which cannot know them; `sessions`, the first span of each session the agent saw, which it keeps across its restarts; `catalog`, a newer catalog the agent accepted (catalogProblem finds nothing in it), whose additions the sets take
* @param {{ offsets?: boolean, sessions?: Map<string, { first: bigint, seen: number }>, catalog?: any, filterVersion?: string }} [options] `offsets: false` leaves out the places, as the collector, which cannot know them; `sessions`, the first span of each session the agent saw, which it keeps across its restarts; `catalog`, a newer catalog the agent accepted (catalogProblem finds nothing in it), whose additions the sets take; `filterVersion`, the study's version, stamped on each resource
*/
function createTransform(allowlist, key, { offsets = true, sessions, catalog } = {}) {
function createTransform(allowlist, key, { offsets = true, sessions, catalog, filterVersion } = {}) {
if (catalog !== undefined && catalogProblem(catalog)) throw new Error(`The catalog is refused: ${catalogProblem(catalog)}.`);
const rules = compile(catalog === undefined ? allowlist : withCatalogSets(allowlist, catalog));
const hash = typeof key === "string" && /^[0-9a-f]{32,128}$/.test(key) ? keyedHash(key) : undefined;
const sessionOffset = offsets ? sessionOffsets(Date.now, sessions) : undefined;
return (signal, request) => {
if (signal !== "traces" || hash === undefined) return null;
try {
return transformTraces(rules, request, { hash, sessionOffset });
return transformTraces(rules, request, { hash, sessionOffset, filterVersion });
} catch {
return null;
}
Expand All @@ -1019,10 +1031,10 @@ try {
key = undefined;
}

export default createTransform(allowlist, key);
export default createTransform(allowlist, key, { filterVersion: version });

/** The same filter with another key, as `preview` runs it; without the places in sessions with `{ offsets: false }`; with a newer catalog's sets with `{ catalog }`. */
export const filter = (other, options) => createTransform(allowlist, other, options);
/** The same filter with another key, as `preview` runs it; without the places in sessions with `{ offsets: false }`; without its version on each span with `{ filterVersion: undefined }`; with a newer catalog's sets with `{ catalog }`. */
export const filter = (other, options) => createTransform(allowlist, other, { filterVersion: version, ...options });

/** The catalog this filter was generated with: its form, its date, and the releases it was read from. */
export const catalog = { schema: catalogSchema, published: allowlist.catalogPublished, releases: allowlist.releases };
Expand Down