Implementing Sentry

From Valve Developer Community
Jump to navigation Jump to search
Todo: This implementation of Sentry Native to Source SDK 2013 is kind of basic, any community edits are appreciated. Otherwise make a pull request at the GitHub repository + this article sucks so again any community edits are appreciated.

If you have any issues with the implementation, make an issue at the GitHub repository and I or someone else can help you out!

Warning.pngWarning:Sentry Native binaries distributed are only for Windows x64 and x86. If you want to use this in Linux you have to compile the source code for Sentry Native. You can get it at getsentry/sentry-native
Warning.pngWarning:This implementation may only work for Windows and is NOT likely working for Linux.

Implementing Sentry Native into your Source 2013 mod is simple, you can track crashes/errors from the player's session. (don't even use this for a singleplayer mod tho, its not worth it.) Before we dig down into the tutorial of how to implement Sentry into your Source mod, you obviously need to know about what is Sentry.

Note.pngNote:This is just a replacement to the "Breakpad" crash handler that the Steam API is using.

What is Sentry?

Sentry is a software tool that helps developers monitor application performance and track errors. It provides code-level visibility into errors, release health, and performance. (i used AI to generate this, omg i'm going be a pro wiki writer)

See https://sentry.io/about for more info about Sentry.

Getting the libraries and code

Now, we're going to get the Sentry Native libraries and the implementation code.

You can go download the ZIP file for the implementation at https://github.com/PracticeMedicine/sentry-source-engine/releases/tag/v1.0.0

Implementation

Since your here, I assume that you have the ZIP file downloaded and extracted, and now.

First, copy the contents of the extracted ZIP's "src" folder to your mod source code's "src" folder.

And then, edit your mod's "client" and "server" VPC script file (e.g. client_mymod.vpc, client_hl2.vpc). Use your favorite text editor. (I use VS Code or Notepad++)

This step is optional since you can just add an existing item to the project but if you want to make it so that it adds the file in every creation of projects then you have the follow through this step.

For the client side, once your in the client VPC script you have to add this into the top of your script (ignore the periods):

...
$Include "$SRCDIR\game\shared\sentry.vpc"
...

For the server side, you gotta do the same thing as we did at the client script. (again ignore the periods):

...
$Include "$SRCDIR\game\shared\sentry.vpc"
...

Okay now, recreate the projects by running the "createallprojects.bat" batch file. Once the projects are recreated, open "everything.sln" with Visual Studio 2022.

Once your in the solution, there's a change that we needed to do before we compile the mod.

Open the "sentry_mgr.cpp" code (located at Source files -> Sentry -> sentry_mgr.cpp).

Go to around line 22 and you'll see these definitions on the code:

// replace this with your Sentry project's DSN link
#define SENTRY_DSN_LINK "<your-dsn-link-here>"
// replace this with anything you want
#define SENTRY_RELEASE "mymod@version"
// replace this with anything you want
#define SENTRY_ENVIRONMENT "development"

As the comment explains, replace the value with you already know.

Now finally, build the solution by right-clicking the solution and then click "Build Solution" otherwise press CTRL + SHIFT + B.

While we're at it, put the following files that is in the src/thirdparty/sentry_native/bin to your mod's "bin" directory:

  • aridity_crashpad.exe
  • crashpad_wer.dll
  • sentry.dll

Once it finishes building the projects, copy the compiled DLLs into your mod's "bin" folder if it's in a different directory like the "sourcemods" folder.

You can sanity check it by running the mod. You can tell that Sentry has been initialized if:

  • 2 instances of aridity_crashpad.exe is running alongside of the mod's executable.
  • Console messages confirming that Sentry has been initialized.

You can also sanity check it by executing GetSentryMgr()->SentryInfo("Test Logging", "Hello world!"); at CHLClient::Init() or something and then check the Sentry dashboard if that event was sent.

Conclusion

Congratulations! You have implemented Sentry Native into your Source mod! AKA as I liked to call it: A replacement to Steam/Source's shitty crash-reporter (yes there's a crash-reporter already built-in but its using the "Breakpad" crash handler which is a predecessor for "Crashpad".)

Note to everyone: please don't even use this implementation to stalk people.