* Build OTLP span attributes for the active experiment assignments. * * Adds one `gh-aw.experiment. ` attribute per experiment (carrying the * selected variant string) and a single `gh-aw.experiments` attribute with a * compact JSON string of only the valid emitted assignments (key-sorted f
(assignments)
| 689 | * @returns {Array<{key: string, value: object}>} |
| 690 | */ |
| 691 | function buildExperimentAttributes(assignments) { |
| 692 | if (!assignments || typeof assignments !== "object") return []; |
| 693 | const names = Object.keys(assignments).sort(); |
| 694 | if (names.length === 0) return []; |
| 695 | const attrs = []; |
| 696 | /** @type {Record<string, string>} */ |
| 697 | const validAssignments = {}; |
| 698 | for (const name of names) { |
| 699 | const variant = assignments[name]; |
| 700 | if (typeof variant === "string" && variant) { |
| 701 | attrs.push(buildAttr(`gh-aw.experiment.${name}`, variant)); |
| 702 | validAssignments[name] = variant; |
| 703 | } |
| 704 | } |
| 705 | if (attrs.length > 0) { |
| 706 | attrs.push(buildAttr("gh-aw.experiments", JSON.stringify(validAssignments))); |
| 707 | } |
| 708 | return attrs; |
| 709 | } |
| 710 | |
| 711 | // --------------------------------------------------------------------------- |
| 712 | // Custom OTLP attributes (GH_AW_OTLP_ATTRIBUTES) |
no test coverage detected