Skip to content

Commit 8609777

Browse files
committed
New post
1 parent bdd0172 commit 8609777

10 files changed

+131
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ _site
55
vendor/bundle
66

77
*.iml
8+
.idea

_layouts/post.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<article class="post h-entry" itemscope itemtype="http://schema.org/BlogPosting">
55

66
<header class="post-header">
7-
<h1 class="post-title p-name fs-3" itemprop="name headline">{{ page.title | escape }}</h1>
7+
<h1 class="post-title p-name fs-3 mt-3" itemprop="name headline">{{ page.title | escape }}</h1>
88

99
<div class="my-3 text-uppercase text-truncate">
1010
{%- assign date_format = site.minima.date_format | default: "%b %-d, %Y" -%}

_posts/2021-10-03-spt-development-audit-spring.markdown

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ In this post I introduce the features of [spt-development-audit-spring](https://
1414
{: class="lead"}
1515

1616
## Demo project
17-
{: class="fs-3" }
17+
{: class="fs-4" }
1818

1919
The demo project provides a simple 'books' REST API backed by and in-memory H2 database with basic authentication configured with Spring Security. Once running, the REST API can then be exercised with cURL as follows:
2020

@@ -23,12 +23,12 @@ The demo project provides a simple 'books' REST API backed by and in-memory H2 d
2323
See the [README](https://github.com/spt-development/spt-development-demo/blob/main/README.md) for more detail.
2424

2525
## Auditing
26-
{: class="fs-3" }
26+
{: class="fs-4" }
2727

2828
There are many reasons why you might want to add auditing to your application. The main reason we wanted to add auditing to [SPT Contractors](https://spt.contractors/) was to be able to trace through how records reached a particular state; having this information has been invaluable on past projects for replaying when things go wrong and answering user queries when records are in a state they don't expect. We wanted an auditing solution that was simple to implement without polluting my business logic with calls to persist the audit records. Additionally, we wanted another service to be responsible for persisting the audit records which could potentially be extended to perform analysis or transformations at a later date. Out of these requirements `spt-development-audit-spring` was born.
2929

3030
## spt-development-audit-spring
31-
{: class="fs-3" }
31+
{: class="fs-4" }
3232

3333
The demo project uses the `spt-development-audit-spring-boot-starter` to pull in the required dependencies and automatically configure the auditor. The demo project also has a dependency on the [spt-development-cid-web-spring-boot](https://github.com/spt-development/spt-development-cid-web-spring-boot) starter in order to pull in and configure `spt-development-cid-web` and its dependencies so that the correlation ID on the audit event records is set correctly (see [earlier post]({% post_url 2021-05-30-spt-development-cid-part-2 %}) for more details). The demo project also uses the [spt-development-logging-spring-boot](https://github.com/spt-development/spt-development-logging-spring-boot) starter (also discussed in my earlier post) and the [spt-development-cid-jms-spring-boot](https://github.com/spt-development/spt-development-cid-jms-spring-boot) starter that I will talk about in greater depth, later in this post.
3434

@@ -57,14 +57,14 @@ Multiple parameters can be annotated with `@Audited.Detail` but if you do, the `
5757
The `spt-development-audit-spring-boot-starter` configures the `Slf4jAuditEventWriter` bean by default, which is an instance of the `AuditEventWriter` interface. In a production service you probably want your adit event records persisted to some kind of database, in which case you will need to create a bean that is an instance of `AuditEventWriter` or if your service methods are transactional, an instance of `TransactionAwareAuditEventWriter` so that the audit events are only written if the transaction is successfully committed. For SPT Contractors, we developed a separate service responsible for persisting the audit event records read from a JMS queue and would recommend this approach in general. Creating a `JmsTemplate` bean and setting the `spt.audit.jms.destination` property results in the `spt-development-audit-spring-boot-starter` instantiating a `JmsAuditEventWriter` bean which writes the audit event records to the configured JMS queue, rather than to the logs with `Slf4jAuditEventWriter`. The demo project uses an in-memory Artemis JMS queue to demonstrate this.
5858

5959
## Actuator audit events
60-
{: class="fs-3" }
60+
{: class="fs-4" }
6161

6262
It is very straight forward to integrate `spt-development-auditor` with [Actuator Auditing](https://docs.spring.io/spring-boot/docs/2.5.5/reference/html/actuator.html#actuator.auditing) which allows you to treat business audit events and actuator audit events (for example generated by Spring Security) in a consistent manner. Simply create a class that extends `AbstractAuditListener` inject a `AuditEventWriter` bean and in the `AbstractAuditListener::onAuditEvent()` method write the audit events with the audit event writer. The demo project uses this approach to audit successful and unsuccessful login attempts.
6363

6464
{% gist bf66f89f8c3e49d23bb4850255c76814 %}
6565

6666
## spt-development-cid-jms-spring
67-
{: class="fs-3" }
67+
{: class="fs-4" }
6868

6969
`spt-development-cid-jms-spring` integrates `spt-development-cid` into a Spring JMS (listener) project, initialising the correlation ID from the correlation ID of the received JMS message. The demo project shows the easiest way to integrate `spt-development-cid-jms-spring` into a Spring Boot application, with `spt-development-cid-jms-spring-boot-starter`. If your listener methods have a single `Message` parameter, there is nothing further to do. If your listener methods accept a `@Payload` annotated parameter, they will need an additional parameter annotated with the `@Header` annotation and the name set to `jms_correlationId` as shown in the `AuditListener::onMessage` method of the demo project.
7070

_posts/2022-04-11-spt-development-release.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Just to reiterate, there is nothing wrong with versions 2.0.1 to 2.0.11 other th
2121
{: class="lead"}
2222

2323
## Automated Release
24-
{: class="fs-3" }
24+
{: class="fs-4" }
2525

2626
Below is a summary of some of the problems we ran into whilst trying to automate the release process with
2727
[Travis CI](https://www.travis-ci.com) and the solutions we found.
2828

2929
### `maven-release-plugin` requires full clone of repository
30-
{: class="fs-4" }
30+
{: class="fs-5" }
3131

3232
`mvn release:prepare release:perform -B` will update the versions and kick off the Maven `deploy` phase - we already had
3333
the relevant plugins configured to deploy to sonatype with `mvn deploy -Prelease`. Out of the box, Travis performs
@@ -41,22 +41,22 @@ The other commands in the install phase are used to capture the version number f
4141
signing the jars uploaded to Sonatype.
4242

4343
### Deploy stage requires values from maven `settings.xml`
44-
{: class="fs-4" }
44+
{: class="fs-5" }
4545

4646
Add encrypted environment variables and reference them in a custom settings file referenced with the `--settings`
4747
mvn parameter.
4848

4949
{% gist 08ac0b5568df5e96510dd5025d3194d3 %}
5050

5151
### Inability to encrypt special characters in environment variables properly
52-
{: class="fs-4" }
52+
{: class="fs-5" }
5353

5454
`cd` to a clone of the repository and use the following command, entering `ENV_VAR=value` when prompted:
5555

5656
{% gist 076ce4d2d6597d7f96ee94b49c519fa6 %}
5757

5858
### Prevent checkins by `maven-release-plugin` kicking off another build (and release)
59-
{: class="fs-4" }
59+
{: class="fs-5" }
6060

6161
Use the `scmCommentPrefix` setting of `maven-release-plugin` to include `[skip travis]`.
6262

@@ -67,7 +67,7 @@ Note also the `goals` configuration setting with the value `deploy`. If a distri
6767
To upload to Github, we need to use the releases provider; specifying `deploy` runs the `deploy` phase instead.
6868

6969
### Create the release in Github
70-
{: class="fs-4" }
70+
{: class="fs-5" }
7171

7272
The Travis [Github releases provider](https://docs.travis-ci.com/user/deployment/releases/) makes this straight forward,
7373
however it is tightly coupled to tagging a particular version of the code. In order to prevent an infinite loop of

_posts/2022-09-24-dance-dad-burning-cds.markdown

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ to use [ffmpeg](https://ffmpeg.org/) to convert the downloaded file from [mp4](h
1818
[mp3](https://en.wikipedia.org/wiki/MP3), before using [Apple Music](https://en.wikipedia.org/wiki/Apple_Music) to burn the music to CD.
1919

2020
## Downloading audio files from Facebook Messenger
21-
{: class="fs-3" }
21+
{: class="fs-4" }
2222

2323
Facebook used to make it fairly straight forward to download audio files from Messanger, for some reason they now make it as difficult as
2424
possible. These steps were performed in Google Chrome on Mac OS, but shouldn't vary too much from browser to browser, or OS to OS. They
2525
will need to be performed on a desktop rather than mobile device however.
2626

2727
### 1. Open messages
28-
{: class="fs-4" }
28+
{: class="fs-5" }
2929

3030
Browse to the messages containing the audio file(s).
3131

3232
![facebook messenger](/assets/images/2022-09-24-dance-dad-burning-cds/facebook-messenger.jpeg){:class="img-fluid"}
3333

3434
### 2. Open up browser dev tools
35-
{: class="fs-4" }
35+
{: class="fs-5" }
3636

3737
Hit F12 or however you prefer to open the browser dev tools and then select the network tab.
3838

3939
![idev tools](/assets/images/2022-09-24-dance-dad-burning-cds/dev-tools.jpeg){:class="img-fluid"}
4040

4141
### 3. Play the audio file
42-
{: class="fs-4" }
42+
{: class="fs-5" }
4343

4444
Click on the audio file to start it playing. If you have already played it, then refresh the Facebook Messenger page first and clear out the
4545
network history to make it easier to see which audio file was downloaded when you hit play. Then right click the audio file that appears
@@ -52,7 +52,7 @@ I found no way of tying an mp4 file to a particular message, so I had to right c
5252
one I wanted.]
5353

5454
## Converting mp4 to mp3
55-
{: class="fs-3" }
55+
{: class="fs-4" }
5656

5757
If you received an mp3 file, this step can be skipped. If you received an mp4 for example, then you will need to convert it
5858
to an mp3 file. If you try buring an mp4 file to CD, you will find that only the first 6 seconds gets written to the CD. I used ffmpeg
@@ -61,10 +61,10 @@ that I had previously installed with [brew](https://formulae.brew.sh/formula/ffm
6161
{% gist c65fe53fa7f379108e3fe6e956254c48 %}
6262

6363
## Burning the audio file to CD
64-
{: class="fs-3" }
64+
{: class="fs-4" }
6565

6666
### 1. Create a new playlist
67-
{: class="fs-4" }
67+
{: class="fs-5" }
6868

6969
Open Apple Music and create a new playlist.
7070

@@ -73,14 +73,14 @@ Open Apple Music and create a new playlist.
7373
![new playlist](/assets/images/2022-09-24-dance-dad-burning-cds/new-play-list-2.jpeg){:class="img-fluid"}
7474

7575
### 2. Add the audio file to the playlist
76-
{: class="fs-4" }
76+
{: class="fs-5" }
7777

7878
Find the previously downloaded/converted file in finder and drag it and drop it on to the newly created playlist in Apple Music.
7979

8080
![new playlist](/assets/images/2022-09-24-dance-dad-burning-cds/new-play-list-3.jpeg){:class="img-fluid"}
8181

8282
### 3. Burn the CD
83-
{: class="fs-4" }
83+
{: class="fs-5" }
8484

8585
With a blank CD already inserted into the CD burner, right click the newly created playlist and select "Burn Playlist to Disc..."; in
8686
the dialog that is opened, leave the defaults selected and click "Burn" - the "Audio CD" format seems to be the most likely format to work,
@@ -91,6 +91,6 @@ in a random CD player, but make sure you test the burnt CD!
9191
![burn cd](/assets/images/2022-09-24-dance-dad-burning-cds/burn-cd-2.jpeg){:class="img-fluid"}
9292

9393
### 4. Test the CD!!!
94-
{: class="fs-4" }
94+
{: class="fs-5" }
9595

9696
I tested it in an old CD player to give confidence that it will probably work at the dance festival.

_posts/2022-10-26-spt-development-release.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Additionally, the following libraries have also been updated:
3535
We have also upgraded the [demo project](https://github.com/spt-development/spt-development-demo) to v2.0.10 of all the libraries above.
3636

3737
### Mapped Diagnostic Context
38-
{: class="fs-4" }
38+
{: class="fs-5" }
3939

4040
Simply adding v2.0.10 spt-development-cid-web-spring-boot-starter or spt-development-cid-jms-spring-boot-starter (depending on your requirements)
4141
as a dependency to your project, will be enough to have the correlation ID added to the [Mapped Diagnostic Context](https://logback.qos.ch/manual/mdc.html)
@@ -59,7 +59,7 @@ shows the changes made to the demo project to remove the explicit inclusion of c
5959
spt-development-logging-spring-boot, the number of changes will be reduced.
6060

6161
#### Disable MDC
62-
{: class="fs-5" }
62+
{: class="fs-6" }
6363

6464
Although it is the default functionality and recommended approach, if you don't want to use MDC, maybe because you already have `CorrelationId.get()` calls
6565
in log statements scattered throughout your code, then it it is possible to disable this new functionality by setting the `spt.cid.mdc.disabled` property to `true`.
@@ -68,7 +68,7 @@ is purely for demonstration and testing purposes however and not expected to be
6868
no reason why it couldn't be.
6969

7070
### Why the U-turn
71-
{: class="fs-4" }
71+
{: class="fs-5" }
7272

7373
It was a conscious decision [early on]({% post_url 2021-05-30-spt-development-cid-part-2 %}) *not* to use the MDC. However, having had feedback from various
7474
users, it became eveident that this was a feature that was lacking in the library and having to explicitly add `CorrelationId.get()` explicitly to log

_posts/2023-05-14-micrometer-trace-integration.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ excerpt: |
2121
{{ page.excerpt | remove: '<span class="d-inline d-md-none d-xl-inline">' | remove: '</span>' }}
2222

2323
## Micrometer Tracing
24-
{: class="fs-3" }
24+
{: class="fs-4" }
2525

2626
All of the code from this post can be found in the
2727
[spt-development-micrometer-tracing-demo](https://github.com/spt-development/spt-development-micrometer-tracing-demo) project, which was forked
@@ -43,7 +43,7 @@ Spring Boot samples only 10% of requests to prevent overwhelming the trace backe
4343
property; this is not necessary for this demo where we are only logging to the console.
4444

4545
### Gotcha!
46-
{: class="fs-4" }
46+
{: class="fs-5" }
4747

4848
One thing that I struggled to find mentioned in the documentation was that tracing is *switched off* by default in tests. This is
4949
[intended](https://github.com/spring-projects/spring-boot/issues/31308){:target="_blank"} and therefore when I ran the tests initially, the trace
@@ -53,7 +53,7 @@ annotation to the integration tests, which can be used to enable/disable metrics
5353
{% gist b785e325630c7dcb1eeaefab50df29b0 %}
5454

5555
## Auditing
56-
{: class="fs-3" }
56+
{: class="fs-4" }
5757

5858
Adding the `spt-development-audit-spring-boot-starter` dependency to the project pulls in the required dependencies and automatically configures the
5959
auditor. Since we are going to be using the Micrometer trace ID in place of the correlation ID, we can exclude the `spt-development-cid`
@@ -70,15 +70,15 @@ With this in place and methods annotated as described in [this post]({% post_url
7070
fully audited and audit events can be correlated using the trace ID.
7171

7272
### Actuator audit events
73-
{: class="fs-4" }
73+
{: class="fs-5" }
7474

7575
If you are capturing actuator events as described in the previous [auditing post]({% post_url 2021-10-03-spt-development-audit-spring %}) you
7676
need to inject the `Tracer` bean into your audit event listener and again use the current trace ID in place of the correlation ID.
7777

7878
{% gist c7af3532347d0d14fb35646d27d88eae %}
7979

8080
### JMS Propagation
81-
{: class="fs-4" }
81+
{: class="fs-5" }
8282

8383
The demo project makes use of `JmsAuditEventWriter` simply by configuring the `spt.audit.jms.destination` property. The Micrometer trace context
8484
is not currently propagated in JMS messages by default; there is currently an
@@ -90,7 +90,7 @@ the correlation ID returned by the `CorrelationIdProvider`.
9090
{% gist e442d6398602902177ff622bcfbf786e %}
9191

9292
## Logging
93-
{: class="fs-3" }
93+
{: class="fs-4" }
9494

9595
As previously written about in more detail [here]({% post_url 2021-05-30-spt-development-cid-part-2 %}) simply add the `spt-development-logging-spring-boot-starter`
9696
as a dependency to get production quality logging added to your application without any further code changes. With the logging format changes above, you will then

_posts/2024-07-14-spring-boot-3.3.1-starters-available-now.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ We have also upgraded the [demo project](https://github.com/spt-development/spt-
4141
[Micrometer demo project](https://github.com/spt-development/spt-development-micrometer-tracing-demo) to Spring Boot 3.3.1 and v3.3.1 of all the libraries above.
4242

4343
### spt-development-logging-spring - Arbitrary bean logging support
44+
{: class="fs-5" }
4445

4546
Release 3.2.0 of `spt-development-logging-spring` introduces support for logging public methods of arbitrary beans. This logging is enabled by adding the
4647
`EnableBeanLogging` annotation to your project. The `includeBasePackageClasses` must contain at least one class and enables logging of Spring beans from the same package as any of the classes specified.

0 commit comments

Comments
 (0)