• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 25565075335

08 May 2026 03:47PM UTC coverage: 92.787% (-0.1%) from 92.887%
25565075335

push

github

web-flow
add OpenTelemetry backend for work unit reporting (#23284)

# Overview

Add a new `pants.backend.observability.opentelemetry` backend to report
work unit tracing to OpenTelemetry. The backend is based on
[shoalsoft-pants-opentelemetry-plugin](https://github.com/shoalsoft/shoalsoft-pants-opentelemetry-plugin)
with unnecessary compatibility code and "shoalsoft" branding removed.

Notes:
- This backend only reports Pants engine work units to OpenTelemetry; it
does not report tracing data for Pants rule code or Rust code.
- This backend does not support gRPC export due to fork safety issues
with the gRPC C library and Python. See
https://github.com/shoalsoft/shoalsoft-pants-opentelemetry-plugin/issues/84
and https://github.com/grpc/grpc/blob/master/doc/fork_support.md for
additional details.

# Lockfile

```
    Lockfile diff: 3rdparty/python/user_reqs.lock [python-default]

    ==                    Upgraded dependencies                     ==

      anyio                          4.12.1       -->   4.13.0
      certifi                        2026.1.4     -->   2026.4.22
      charset-normalizer             3.4.4        -->   3.4.7
      click                          8.3.1        -->   8.3.2
      cross-web                      0.4.1        -->   0.6.0
      cryptography                   46.0.5       -->   46.0.7
      graphql-core                   3.2.7        -->   3.2.8
      idna                           3.11         -->   3.12
      librt                          0.8.1        -->   0.9.0
      pydantic                       2.12.5       -->   2.13.3
      pydantic-core                  2.41.5       -->   2.46.3
      pygments                       2.19.2       -->   2.20.0
      pyjwt                          2.11.0       -->   2.12.1
      python-dotenv                  1.2.1        -->   1.2.2
      python-multipart               0.0.22       -->   0.0.26
      ujson                          5.11.0       -->   5.12.0

    ==                   ... (continued)

564 of 740 new or added lines in 12 files covered. (76.22%)

1 existing line in 1 file now uncovered.

92944 of 100169 relevant lines covered (92.79%)

4.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/src/python/pants/backend/tools/preamble/subsystem.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
1✔
4

5
from collections.abc import Sequence
1✔
6

7
from pants.option.option_types import DictOption, SkipOption
1✔
8
from pants.option.subsystem import Subsystem
1✔
9
from pants.source.filespec import FilespecMatcher
1✔
10
from pants.util.strutil import help_text, softwrap
1✔
11

12

13
class PreambleSubsystem(Subsystem):
1✔
14
    options_scope = "preamble"
1✔
15
    name = "preamble"
1✔
16
    help = help_text(
1✔
17
        """
18
        Formats files with a preamble, with the preamble looked up based on path.
19

20
        This is useful for things such as copyright headers or shebang lines.
21

22
        Pants substitutes the following identifiers (following Python's `string.Template` substitutions):
23
        - $year: The current year (only used when actually writing the year to the file).
24
        """
25
    )
26

27
    skip = SkipOption("fmt")
1✔
28

29
    _template_by_globs = DictOption[str](
1✔
30
        help=softwrap(
31
            """
32
            Which preamble template to use based on the path globs (relative to the build root).
33

34
            Example:
35

36
                {
37
                    '*.rs': '// Copyright (c) $year\\n// Line 2\\n'
38
                    '*.py:!__init__.py': '# Copyright (c) $year\\n# Line 2\\n',
39
                }
40

41
            It might be helpful to load this config from a JSON or YAML file. To do that, set
42
            `[preamble].config = '@path/to/config.yaml'`, for example.
43
            """
44
        ),
45
        fromfile=True,
46
    )
47

48
    @property
1✔
49
    def template_by_globs(self) -> dict[tuple[str, ...], str]:
1✔
50
        return {tuple(key.split(":")): value for key, value in self._template_by_globs.items()}
1✔
51

52
    def get_template_by_path(self, filepaths: Sequence[str]) -> dict[str, str]:
1✔
53
        """Returns a mapping from path to (most-relevant) template."""
54
        filepaths_to_test = set(filepaths)
1✔
55
        template_by_path = {}
1✔
56
        for globs, template in self.template_by_globs.items():
1✔
57
            if not filepaths_to_test:
1✔
UNCOV
58
                break
×
59

60
            matched_filepaths = FilespecMatcher(
1✔
61
                includes=[
62
                    (glob[2:] if glob.startswith(r"\\!") else glob)
63
                    for glob in globs
64
                    if not glob.startswith("!")
65
                ],
66
                excludes=[glob[1:] for glob in globs if glob.startswith("!")],
67
            ).matches(tuple(filepaths_to_test))
68
            filepaths_to_test -= set(matched_filepaths)
1✔
69
            for filepath in matched_filepaths:
1✔
70
                template_by_path[filepath] = template
1✔
71

72
        return template_by_path
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc