An example Golang application demonstrating how to use the WorkOS Golang SDK to send and retrieve Audit Log events. This example is not meant to show a real-world example of an Audit Logs implementation, but rather to show concrete examples of how events can be sent using the Go SDK.
-
Clone the example repository using your preferred secure method (HTTPS or SSH).
# HTTPS git clone https://github.com/workos/go-example-applications.git
or
# SSH git clone [email protected]:workos/go-example-applications.git
-
Navigate to the cloned repository and to the Audit Logs:
cd go-example-applications/go-audit-logs-example
-
Obtain and make note of the following values. In the next step, these will be set as environment variables.
- Your WorkOS API key
- Your WorkOS Client ID
-
Create a new file called ".env" in the root of the project and add the following variables, replacing the xxx with the value from step 3:
- WORKOS_API_KEY=xxx
- WORKOS_CLIENT_ID=xxx
-
The final setup step is to start the server.
go run main.go
You'll know the server is running when you see no errors in the CLI, and output similar to the following is displayed:
launching audit logs demo with configuration: {Addr::8000 Domains:}
Navigate to
localhost:8000
in your web browser to view the example application. Then, click the buttons to see example events after configuring your audit logs in the WorkOS dashboard.
- Follow the Audit Logs configuration steps to set up the following 5 events that are sent with this example:
Action title: "user.signed_in" | Target type: "team" Action title: "user.logged_out" | Target type: "team" Action title: "user.organization_set" | Target type: "team" Action title: "user.organization_deleted" | Target type: "team" Action title: "user.connection_deleted" | Target type: "team"
-
Next, take note of the Organization ID for the Org which you will be sending the Audit Log events for. This ID gets entered into the splash page of the example application.
-
Once you enter the Organization ID and submit it, you will be brought to the page where you'll be able to send the audit log events that were just configured. You'll also notice that the action of setting the Organization triggered an Audit Log already. Click the buttons to send the respective events.
-
To obtain a CSV of the Audit Log events that were sent for the last 30 days, click the "Export Events" button. This will bring you to a new page where you can download the events. Downloading the events is a 2 step process. First you need to create the report by clicking the "Generate CSV" button. Then click the "Access CSV" button to download a CSV of the Audit Log events for the selected Organization for the past 30 days.
If you get stuck and aren't able to resolve the issue by reading our API reference or tutorials, you can reach out to us at [email protected] and we'll lend a hand.