GitHub
Zymtrace can show the source code of profiled functions next to their profiles, fetched from the GitHub repositories they were built from. Source code is shown in the function details of flamegraphs, in the stack traces of recommendations, in Top Functions, and in Diff Functions.
Source code fetched through this integration is visible to every Zymtrace user who can view the related profiling data, regardless of whether that user has access to the code in GitHub. Zymtrace does not check GitHub permissions for individual users.
How it works​
- The profiler reads the repository and commit of each container from the
org.opencontainers.image.sourceandorg.opencontainers.image.revisionlabels of its image, and attaches them to the profiling data assource.locationandsource.revision. - The worker indexes the file tree of every reported repository revision, using the GitHub credentials configured in Zymtrace.
- When you view a function, Zymtrace looks up the file it is defined in within the indexed revisions it ran in. Files are matched by the longest common path suffix, so the directory the code was built or deployed in doesn't need to match the repository layout: a frame in
/build/server/handler.pymatches/app/server/handler.pyin the repository.
Functions need file and line information to be matched. This is available for interpreted languages, while native code requires debug symbols with line information (e.g. with the -dwarf profiler argument).
Setup​
Enable the integration​
The GitHub settings page is hidden behind the GitHub feature flag, which is off by default.
- Open Settings → Feature Flags.
- Turn on GitHub.
The GitHub entry appears under Settings.
Add GitHub credentials​
Zymtrace needs read access to the contents of the repositories you profile. This can be either a GitHub App (recommended) or a personal access token. GitHub Enterprise Server and GHE.com instances are supported by setting the GitHub URL of the credential to the URL of your instance. For public third party repositories that an app cannot be installed into, an access token is required.
GitHub App​
A GitHub App is not tied to a user, refreshes its access tokens automatically, and gets a higher API rate limit than a personal access token.
-
Open Settings → GitHub, and click Create GitHub App under GitHub App.
-
Read and accept the source code access notice.
-
Enter the URL of your GitHub instance, and the organization that should own the app. Leave the organization empty to register the app on your own account.
noteCheck Allow installing on other organizations and users to index the repositories of more than one organization with the same app.
-
Click Continue to GitHub, and create the app on GitHub. GitHub returns you to Zymtrace, which adds the app to the credentials.
-
Click Install it, and install the app on the organizations (or selected repositories) that should be indexed.
Access token​
- Create a personal access token on GitHub:
- Fine-grained tokens need the Contents: read permission on the repositories to index.
- Classic tokens need the
reposcope. Public repositories need no scope.
- Open Settings → GitHub, and click Add credential.
- Choose what the token applies to under Match: a whole GitHub Instance, an Organization, or a single Repository.
- Select Access token as the credential, and enter the token.
- Click Save changes. Zymtrace checks that the token has the required access before saving it.
Credential order​
Credentials are checked from top to bottom, and the first one that matches a repository is used. GitHub Apps that are not installed for the repository are skipped. Repositories without a matching credential are not indexed.
Label your container images​
Set both labels when building the image, using the full commit SHA (short SHAs and tags are not supported). For example, setting the labels via the command line:
docker build \
--label org.opencontainers.image.source=https://github.com/<org>/<repo> \
--label org.opencontainers.image.revision=$(git rev-parse HEAD) .
On Kubernetes, the same keys can also be set as pod annotations. Container labels take precedence over pod annotations.
To read the repository and commit from other label or annotation keys, use the -source-labels and -revision-labels profiler arguments. See Profiler ENV & CLI Args.
Viewing source code​
- Flamegraphs: hovering a frame shows whether its source file was found. Selecting it opens the function details, with the source lines around the function and the stack trace of the frame. The source can also be opened in the full code explorer, or on GitHub.
- Top Functions: opens the file of the function in the code explorer, at the function's definition.
- Diff Functions: shows the function's file in the baseline and comparison revisions side by side, with the changes highlighted.
- Recommendations: the stack traces of a recommendation show the source of their frames.
If a function ran in more than one revision, or its file name matches several files in the repository, pick one from the revision selector next to the source.
Profiles can also be grouped by Source Location and Source Revision in the flamegraph, and filtered by source.location and source.revision in the query bar.
Troubleshooting​
| Message | Cause |
|---|---|
| No source metadata | The processes running the function report no repository and revision. Check the labels of the container image. |
| Source not indexed | The repository revision has not been indexed (yet), usually because no credential matches the repository or the credential lacks access. |
| No matching source file | No file in the indexed revisions ends with the frame's file path. |