Commit Graph

63 Commits

Author SHA1 Message Date
Jamie Tanna 0879ce538f feat(instrumentation): add support for protobuf + gRPC exporter (#45527)
As noted in #36073, having support for the different protocols for
exporting OpenTelemetry data would be useful, especially if this is
leading to users seeing issues when they have auto-injected
configuration being set.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-28 11:28:53 +00:00
Sebastian Poxhofer fbedd41e82 test: replace env operation with vi.stubEnv() (#45490)
* test: replace manual process.env mutation with vi.stubEnv

Enable Vitest's `unstubEnvs` so env stubs are reverted automatically
before every test, and convert the manual `process.env.X = ...` /
`delete process.env.X` pairs in specs to `vi.stubEnv()`.

This removes the hand-written `afterEach` cleanup blocks and the
`const OLD_ENV = process.env` / `process.env = { ...OLD_ENV }`
save-restore dance, which silently leaked state between tests when a
test set a variable without a matching delete.

Left as-is (incompatible with `unstubEnvs`, which unstubs before each
test, not after):
- module top-level env writes (cocoapods, gomod, post-update, pip-compile
  and bundler artifacts specs)
- `beforeAll` env writes -- the two in `util/http` moved to `beforeEach`

* test: stop asserting on ambient environment variables

Three specs asserted on values that the surrounding environment can
override, so they only passed on a machine that happened not to set them:

- `util/exec/env`: `getChildProcessEnv()` forwards every entry of
  `basicEnvVars`, but the spec only seeded a subset. Any other forwarded
  variable that was set ambiently (e.g. a lowercase `http_proxy`) leaked
  into the `toEqual` assertion. Clear all of them first.
- `util/git/index`: `process.env.GIT_SSH_COMMAND` deliberately overrides
  the default that the two env-inheritance tests assert on. Clear it.
- `logger/pretty-stdout`: the colorized level strings are built at import
  time, so the `beforeEach` setting `FORCE_COLOR` could never affect them
  -- it was dead code, and the test silently assumed a terminal without
  colour support. Derive the expectation the same way the module does.

* test(datasource/nuget): use a throwaway cache dir for nupkg downloads

The `determine source URL from nupkg` tests do not mock the filesystem,
so they really wrote downloaded packages into a fixed `/tmp/cache` path.
That fails wherever the system tmpdir is not writable, and two checkouts
running the suite at once would share the same directory.

Use `tmp.dir({ unsafeCleanup: true })` and clean it up afterwards, which
is the pattern the other specs that touch disk already use.

* feat(lint): add renovate/prefer-stub-env rule

Enforces in specs what the migration to `vi.stubEnv` established:

- assigning to or deleting `process.env.X` inside `beforeEach`, `afterEach`,
  `it` or `test` is reported, with a fixer that rewrites it to `vi.stubEnv()`
- module scope, `describe` bodies and `beforeAll` / `afterAll` are left alone:
  `unstubEnvs` reverts stubs *before* each test, so a stub created there is
  gone by the time the first test runs, and those must keep assigning directly
- replacing the `process.env` object is reported everywhere and never fixed.
  `vi.stubEnv()` captures the original object when the worker starts, so after
  a reassignment its deletes silently target the old object

The rule found 28 further violations in specs the earlier sweep missed, since
that one was anchored on `delete process.env`. Twelve were auto-fixed; the
rest replaced `process.env` wholesale and are now `clearEnv()` from test/util.

`util/exec/index.spec.ts` opts out with a comment: it asserts on the whole
child env, and `vi.stubEnv()` cannot express that because it maps `PROD`,
`DEV` and `SSR` onto '' instead of deleting them.
2026-08-28 09:26:20 +00:00
Jamie Tanna adbc20e88e feat(instrumentation): allow exporting OTLP JSON file (#42284)
* feat(instrumentation): allow exporting OTLP JSON file

We've recently been investing in improvements to Renovate's
OpenTelemetry instrumentation to improve debuggability and
supportability.

However, not everyone has an immediately available OpenTelemetry
Collector, so the added instrumentation isn't useful to those users.

Instead, we can provide a way to export to the OTLP file format, which
provides a means to export the data to disk and then consume it later.

This will also support use-cases like running in a CI platform like
GitHub Actions and GitLab CI, where OpenTelemetry Collectors may not be
exposed in that environment, but a post-run execution can export it.

We now need to make sure that `RENOVATE_USE_CLOUD_METADATA_SERVICES` is
never set, as `isTracingEnabled` will now resolve true, and the Cloud
Metadata Resource Detectors will be used.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! feat(instrumentation): allow exporting OTLP JSON file

* fixup! fixup! feat(instrumentation): allow exporting OTLP JSON file

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! feat(instrumentation): allow exporting OTLP JSON file

---------

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
2026-07-22 12:26:16 +00:00
Michael Kriese 954ec4f524 refactor(logger): use expose to load bunyan (#42714) 2026-04-17 11:56:48 +00:00
Jamie Tanna 63618c6b8b fix(instrumentation): re-add span_id and trace_id to logs (#42647)
As part of recent changes to how our logger is initialised, we
accidentally broke the propagation of OpenTelemtry `span_id` and
`trace_id` into the Bunyan log context.

We already registered `BunyanInstrumentation`, but because of the
`import`, the instrumentation could not man-in-the-middle the import and
register the instrumentation.

This is slightly more complex, and brittle, test, but does capture the
current behaviour of `BunyanInstrumentation`, if it were removed.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
2026-04-15 17:26:14 +00:00
Mike Ryan f635ae29c4 chore(instrumentation): add timing statistics for getReleases (#42523)
* feat: timing statistics for getReleases

Adds collection and reporting of timing statistics for
`datasource.getReleases()` calls. Each call records the datasource, registryUrl,
packageName, and duration. The intent is to visibility into where
renovate is retrieving release information and how long that might take.

The report consists of a nested data-structure that provides increasing
detail as we descend datasource, registryUrl, and packageName.

The full report  is logged at trace level
`getReleases statistics with packages`.

A summary report including only datasources and registryUrls is logged
at debug level `getReleases statistics summary`.

* add GetReleasesSpanProcessor

- Re-instrument getReleases calls using open telemetry.
- Adds GetReleasesSpanProcessor, which can adapt
  `getReleases` spans to GetReleasesStats.

* fixup instrumentation tests

* pr feedback

* pr feedback: naming

* pr feedback: comments
2026-04-14 17:36:37 +00:00
Felipe Santos 1b58cd65f0 feat(report): add reportFormatting option to format JSON reports with Prettier (#42162)
* feat(report): add `reportFormatting` option to format JSON reports with Prettier

* Avoid mocking prettier in test

* Disable CLI flag
2026-03-30 16:07:36 +00:00
Jamie Tanna 470ee61dd7 fix(instrumentation): always process Git Operation spans (#42119)
* fix(instrumentation): always process Git Operation spans

As part of b5cd0317cf we added the ability
to report the `Git Operations Statistics` at the end of the Renovate
run, by introducing a `SpanProcessor`.

However, this didn't correctly take into account the fact that this
would only be enabled if Renovate was configured to log/export traces,
which is not the case in most deployments.

As noted in #42118, this leads to a blank log line output, which isn't
very useful.

To correct this, we nede to always process these spans, even if tracing
is not enabled.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>

* fixup! fix(instrumentation): always process Git Operation spans

* fixup! fixup! fix(instrumentation): always process Git Operation spans

* fixup! fixup! fix(instrumentation): always process Git Operation spans

---------

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
2026-03-25 12:41:47 +00:00
Jamie Tanna 3f9b23d989 chore(instrumentation): remove TODO (#42133)
As noted by Michael, this was likely fixed as part of other changes he'd
made recently around logging.

Co-authored-by: Michael Kriese <1798109+viceice@users.noreply.github.com>
2026-03-25 11:48:41 +00:00
Sergei Zharinov 41bfb8678e refactor(lint): use oxlint for type-aware rules (#41739)
* feat: enable oxlint type-aware linting

Move type-aware typescript-eslint rules from ESLint to oxlint,
leveraging oxlint-tsgolint for type information. This removes
the need for ESLint's projectService and parserOptions.

- Add `options.typeAware: true` to .oxlintrc.json with all
  type-aware rules (recommendedTypeChecked + stylisticTypeChecked)
- Switch ESLint to non-type-aware configs (recommended, stylistic)
- Remove projectService/parserOptions from ESLint config
- Drop @typescript-eslint/naming-convention (no oxlint equivalent)
- Update oxlint/eslint-plugin-oxlint to 1.51.0
- Add oxlint-tsgolint dependency
- Convert eslint-disable comments to oxlint-disable for type-aware rules
- Fix prefer-optional-chain violations newly caught by oxlint

* fix: revert unnecessary code changes, suppress with oxlint-disable instead

* fix: suppress remaining prefer-optional-chain violations

* fix: suppress last prefer-optional-chain violation

* fix: remove redundant --type-aware CLI flag, use config instead
2026-03-09 12:51:12 +00:00
Michael Kriese 242068db80 fix(instrumentation): ignore docker api auth check (#41548) 2026-02-27 14:10:53 +00:00
Michael Kriese f7efd7d426 feat(instrumentation): allow disabling cloud detectors (#41401)
* feat(otel): allow disabling cloud detectors

* docs(otel): add missing env

* feat: implement `OTEL_NODE_RESOURCE_DETECTORS`

* test: drop snapshot

* Update lib/instrumentation/reporting.spec.ts

Co-authored-by: Jamie Tanna <jamie.tanna@mend.io>

* docs: update otel docs

---------

Co-authored-by: Jamie Tanna <jamie.tanna@mend.io>
2026-02-25 08:10:03 +00:00
Michael Kriese ea089ac660 build: lazy load initialization modules (#41408)
* build: lazy load initialization modules

* test: fix otel test

* test: drop unused
2026-02-23 14:17:18 +00:00
Michael Kriese e34f867da6 feat(otel): support diagnostics debugging (#41362) 2026-02-21 11:33:54 +00:00
Sergei Zharinov 9d857c1f68 refactor(lint): Organize imports with biome (#40966) 2026-02-06 13:40:01 +00:00
Sergei Zharinov 2b0e80b884 feat!: Switch to ESM modules (#40756) 2026-01-29 14:21:41 +00:00
Sergei Zharinov c07814ca4d refactor: Remove decorators for ESM compatibility (#40736)
* refactor: Migrate to decorator alternatives

* refactor: Remove decorators

* Fixes

* build: Remove decorator support from build pipeline

* fix: Remove extra brace in cdnjs getDigest cache key
2026-01-28 13:22:53 +00:00
Sergei Zharinov ad47fd2981 refactor: Extract decorator logic into standalone functions (#40710)
* refactor: Extract decorator logic into standalone `cached()` and `instrumented()` functions

* Update lib/util/cache/package/cached.ts

---------

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2026-01-27 11:18:09 +00:00
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00
Michael Kriese 0785d0b8bc test: add coverage (part2) (#40643) 2026-01-23 20:57:46 +00:00
Jamie Tanna 5d6202249e chore(instrumentation): use stricter type for attributes (#39768)
As we'd missed adding this in ce729a84c4.
2025-12-31 20:07:59 +00:00
Jamie Tanna b2f5049ecb chore(instrumentation): add links to Semantic Convention docs (#39671) 2025-12-01 22:01:43 +00:00
Jamie Tanna b5cd0317cf fix(git): report Git operation statistics at end of run (#39596)
Now we have instrumented our Git operations with tracing, we can make
sure that users who are not using OpenTelemetry still get insights into
their Git operation usage using a debug log output.

Following how other insights are produced, we can introduce a new type
in `lib/util/stats` for `GitOperationStats`, which will track the
overall execution for each operation type, and output them in the same
style as we use for other timing reports.

At the end of a Renovate run, we'll then make sure that this is logged
into a debug log for further investigation.

To create the report, we can make sure that we introduce a new
OpenTelemetry `SpanProcessor`, which will run when we end our Run, and
store any Git operations in `GitOperationStats`.

This adapts code from GPT-4.1 and code from [0].

Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io>

[0]: https://github.com/yurisouza/monitoria-sdk/blob/ca9d751fa7c3a785a04f87b8966bb782b4617021/src/adapters/nestjs/span-duration-tracker.ts#L18-L27
2025-12-01 15:53:26 +00:00
Jamie Tanna 7f6fcfbaaa fix(instrumentation): handle Promise-like objects as Promises (#39661)
When instrumenting, we specifically handle Promises. However, if we have
an object, like SimpleGit's `Response`:

```
export type Response<T> = SimpleGit & Promise<T>;
```

This does not get correctly instrumented, and we end up not waiting for
the function call to complete.

We can make sure we use `isPromise` to correctly check if it's a native
Promise, or something with a Promise-like API.
2025-12-01 14:58:25 +00:00
Jamie Tanna fe8fe42471 chore(instrumentation): add helpers for Git instrumentation (#38582)
As part of being able to fully instrument our Git operations - using
SimpleGit - we can introduce some Git-specific instrumentation helpers.

These helpers will be used as part of a future change, where we will
instrument methods of SimpleGit that we're using.

This provides a set of types which will be used as OpenTelemetry
Attributes to categorise command types.

A number of subcommands that aren't currently deemed to be too important
are bucketed into an `other` category.
2025-12-01 09:51:59 +00:00
Jamie Tanna be7eb13f79 chore(instrumentation): add a decorator for functions (#39621)
As the current method only allows decorating on a class method, but it's
convenient to be able to wrap a whole function.

This isn't technically a decorator, but is a wrapper function.

Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io>
2025-12-01 09:11:57 +00:00
Jamie Tanna ce729a84c4 chore(telemetry): add span attribute for splits (#38633)
As part of a step towards better OpenTelemetry instrumentation as part
of #38609, we can start by introducing a known span attribute for the
repository "split" we're currently processing.

This requires a slight refactor of the `SpanOptions`, to use our custom
type, which enforces the `RenovateSplit` type when using the span name.

This adds it into each of the splits we currently instrument.

Co-authored-by: secustor <sebastian@poxhofer.at>
2025-11-28 12:32:00 +00:00
Jamie Tanna dc046cac54 chore(instrumentation): add a 4-parameter overload (#39588)
Without this, we cannot call `instrument` with the 4 parameters,
otherwise we receive a Typescript error.

Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io>
2025-11-28 09:13:47 +00:00
Michael Kriese 050ac8d23b chore: better code coverage (#39518) 2025-11-25 15:01:54 +00:00
Michele Azzolari 250b18fa54 feat(instrumentation): instrument redis (#39427) 2025-11-20 15:14:06 +00:00
RahulGautamSingh 76f911041a refactor: use named exports (#39196)
* use named exports

* fix test

* add missing imnport

* fix prettier
2025-11-10 12:00:35 +00:00
renovate[bot] b4ed9e65d9 chore(deps): update dependency @vitest/eslint-plugin to v1.3.23 (main) (#38702)
* chore(deps): update dependency @vitest/eslint-plugin to v1.3.23

| datasource | package               | from   | to     |
| ---------- | --------------------- | ------ | ------ |
| npm        | @vitest/eslint-plugin | 1.3.16 | 1.3.23 |

* remove now unnecessary exceptions

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2025-10-31 07:50:48 +00:00
renovate[bot] 1280fe4dc7 chore(deps): update dependency @vitest/eslint-plugin to v1.3.16 (main) (#38502)
* chore(deps): update dependency @vitest/eslint-plugin to v1.3.16

| datasource | package               | from   | to     |
| ---------- | --------------------- | ------ | ------ |
| npm        | @vitest/eslint-plugin | 1.3.13 | 1.3.16 |

* fix linting errors

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2025-10-13 09:24:15 +00:00
Gabriel-Ladzaretti 83570fed11 refactor(libyears): restructure exported type (#35778) 2025-05-08 07:44:13 +00:00
RahulGautamSingh 49fa1be464 feat(util): getEnv (#35161)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2025-05-06 18:37:28 +00:00
seiyar81 12bc4da241 feat(instrumentation): use @opentelemetry resources detectors (#34904) 2025-04-15 10:05:37 +00:00
renovate[bot] 74cc313818 build(deps): update opentelemetry-js monorepo to v2 (main) (major) (#34981)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2025-03-24 22:28:50 +00:00
Michael Kriese 19c115c813 test: cleanup (#34785) 2025-03-13 17:52:09 +00:00
Michael Kriese b5ff90f2bd fix: improve coverage (#34667) 2025-03-06 17:05:19 +00:00
renovate[bot] 5bd5666cc9 chore(deps): update dependency typescript to v5.8.2 (main) (#34582)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2025-03-03 21:31:51 +00:00
Trim21 6e5731b554 test: migrate from jest to vitest (#34499) 2025-02-26 14:18:38 +00:00
Michael Kriese bb5377b3d8 test: fix code coverage (#34495) 2025-02-26 12:40:30 +00:00
Michael Kriese 997c23502e test: migrate to vitest (#34475)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
2025-02-26 09:35:54 +00:00
renovate[bot] d97b010c42 build(deps): update dependency @opentelemetry/semantic-conventions to v1.29.0 (#34217)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2025-02-18 14:47:54 +00:00
Sebastian Poxhofer e78c78a2ef feat(instrumentation/reporting): add libyear support (#34278) 2025-02-18 06:19:21 +00:00
renovate[bot] 64b6e888d0 build(deps): update opentelemetry-js monorepo (#33046)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2024-12-20 20:06:26 +00:00
renovate[bot] 9d8f91c8ef build(deps): update opentelemetry-js monorepo (#32228)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Sergei Zharinov <zharinov@users.noreply.github.com>
2024-10-30 18:58:40 +00:00
Sebastian Poxhofer 8e267a6aca fix(instrumentation/otel): only use strings for span status and record exception (#31481) 2024-09-19 19:44:15 +00:00
Sebastian Poxhofer 3681b2a945 chore: eslint to enforce for typed imports (#30844) 2024-08-19 13:15:27 +00:00
Sergei Zharinov 29b4db980e refactor(instrumentation): Remove unused span parameter (#30861) 2024-08-19 04:52:09 +00:00