Skip to content

Commit 6205485

Browse files
authored
Add make target 'codespell' (#863)
* Add make target 'codespell' * Amend CHANGELOG.md * Amend CHANGELOG.md * Change codespell rule as requested (now broken) * Fix codespell target * Add venv to .codespellignore * Fix entry in CHANGELOG.md * Skip internal/include/libbpf * Fix spelling * Add codespell to precommit deps * Changes to .github/dependabot.yml
1 parent 0a1ea0e commit 6205485

File tree

24 files changed

+102
-20
lines changed

24 files changed

+102
-20
lines changed

.codespellignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mmaped
2+
ect

.codespellrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# https://github.com/codespell-project/codespell
2+
[codespell]
3+
builtin = clear,rare,informal
4+
check-filenames =
5+
check-hidden =
6+
ignore-words = .codespellignore
7+
interactive = 1
8+
skip = .git,go.mod,go.sum,CHANGELOG.md,LICENSES,venv,internal/include/libbpf
9+
uri-ignore-words-list = *
10+
write =

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,12 @@ updates:
217217
schedule:
218218
interval: weekly
219219
day: sunday
220+
- package-ecosystem: pip
221+
directory: /
222+
labels:
223+
- dependencies
224+
- python
225+
- Skip Changelog
226+
schedule:
227+
interval: weekly
228+
day: sunday

.github/workflows/codespell.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: codespell
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
codespell:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Repo
12+
uses: actions/checkout@v4
13+
- name: Codespell
14+
run: make codespell

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
# VSCode
2525
.vscode/
2626

27+
# Installed by `make codespell`
28+
venv/
29+
2730
otel-go-instrumentation
2831
launcher/
2932
opentelemetry-helm-charts/

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ linters-settings:
107107
- name: constant-logical-expr
108108
disabled: false
109109
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
110-
# TODO (#3372) reenable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
110+
# TODO (#3372) re-enable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
111111
- name: context-as-argument
112112
disabled: true
113113
arguments:

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
4646
- Support Go versions from apps defining GOEXPERIMENT. ([#813](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/813))
4747
- Update `net/http` instrumentation to comply with semantic conventions v1.25.0. ([#790](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/790))
4848
- Update existing 3rd party licenses. ([#864](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/864))
49+
- Add make target 'codespell'. ([#863](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/863))
4950

5051
## [v0.12.0-alpha] - 2024-04-10
5152

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ git commit
8585
git push <YOUR_FORK> <YOUR_BRANCH_NAME>
8686
```
8787

88+
Additionally, there is a `codespell` target that checks for common
89+
typos in the code. It is not run by default, but you can run it
90+
manually with `make codespell`. It will set up a virtual environment
91+
in `venv` and install `codespell` there.
92+
8893
Open a pull request against the main `opentelemetry-go-instrumentation` repo. Be sure to add the pull
8994
request ID to the entry you added to `CHANGELOG.md`.
9095

Makefile

+38-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CGO_ENABLED=0
1919
.DEFAULT_GOAL := precommit
2020

2121
.PHONY: precommit
22-
precommit: license-header-check dependabot-generate go-mod-tidy golangci-lint-fix
22+
precommit: license-header-check dependabot-generate go-mod-tidy golangci-lint-fix codespell
2323

2424
# Tools
2525
$(TOOLS):
@@ -208,3 +208,40 @@ check-clean-work-tree:
208208
echo 'Working tree is not clean, did you forget to run "make precommit", "make generate" or "make offsets"?'; \
209209
exit 1; \
210210
fi
211+
212+
# Virtualized python tools via docker
213+
214+
# The directory where the virtual environment is created.
215+
VENVDIR := venv
216+
217+
# The directory where the python tools are installed.
218+
PYTOOLS := $(VENVDIR)/bin
219+
220+
# The pip executable in the virtual environment.
221+
PIP := $(PYTOOLS)/pip
222+
223+
# The directory in the docker image where the current directory is mounted.
224+
WORKDIR := /workdir
225+
226+
# The python image to use for the virtual environment.
227+
PYTHONIMAGE := python:3.11.3-slim-bullseye
228+
229+
# Run the python image with the current directory mounted.
230+
DOCKERPY := docker run --rm -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)
231+
232+
# Create a virtual environment for Python tools.
233+
$(PYTOOLS):
234+
# The `--upgrade` flag is needed to ensure that the virtual environment is
235+
# created with the latest pip version.
236+
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade pip"
237+
238+
# Install python packages into the virtual environment.
239+
$(PYTOOLS)/%: $(PYTOOLS)
240+
@$(DOCKERPY) $(PIP) install -r requirements.txt
241+
242+
CODESPELL = $(PYTOOLS)/codespell
243+
$(CODESPELL): PACKAGE=codespell
244+
245+
.PHONY: codespell
246+
codespell: $(CODESPELL)
247+
@$(DOCKERPY) $(CODESPELL)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ See the [contributing documentation](./CONTRIBUTING.md).
5454
OpenTelemetry Go Automatic Instrumentation is licensed under the terms of the [Apache Software License version 2.0].
5555
See the [license file](./LICENSE) for more details.
5656

57-
Third-party licesnes and copyright notices can be found in the [LICENSES directory](./LICENSES).
57+
Third-party licenses and copyright notices can be found in the [LICENSES directory](./LICENSES).
5858

5959
[OpenTelemetry]: https://opentelemetry.io/
6060
[Go]: https://go.dev/

docs/how-it-works.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ The offsets-tracker generates the [offset_results.json](../internal/pkg/inject/o
109109

110110
### Uretprobes
111111

112-
One of the basic requirments of OpenTelemetry spans is to contain start timestamp and end timestamp. Getting those timestamps is possible by placing an eBPF code at the start and the end of the instrumented function. eBPF supports this requirement via uprobes and uretprobes. Uretprobes are used to invoke eBPF code at the end of the function. Unfortunately, uretprobes and Go [do not play well together](https://github.com/golang/go/issues/22008).
112+
One of the basic requirements of OpenTelemetry spans is to contain start timestamp and end timestamp. Getting those timestamps is possible by placing an eBPF code at the start and the end of the instrumented function. eBPF supports this requirement via uprobes and uretprobes. Uretprobes are used to invoke eBPF code at the end of the function. Unfortunately, uretprobes and Go [do not play well together](https://github.com/golang/go/issues/22008).
113113

114114
We overcome this issue by analyzing the target binary and detecting all the return statements in the instrumented functions. We then place a uprobe at the end of each return statement. This uprobe invokes the eBPF code that collects the end timestamp.
115115

internal/include/go_context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static __always_inline void stop_tracking_span(struct span_context *sc, struct s
106106
void *ctx = bpf_map_lookup_elem(&tracked_spans_by_sc, sc);
107107
if (ctx == NULL)
108108
{
109-
bpf_printk("stop_tracking_span: cant find span context");
109+
bpf_printk("stop_tracking_span: can't find span context");
110110
return;
111111
}
112112

internal/include/otel_types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ volatile const u64 attr_type_int64slice;
3131
volatile const u64 attr_type_float64slice;
3232
volatile const u64 attr_type_stringslice;
3333

34-
/* Defintions should mimic structs defined in go.opentelemetry.io/otel/attribute */
34+
/* Definitions should mimic structs defined in go.opentelemetry.io/otel/attribute */
3535

3636
typedef struct go_otel_attr_value {
3737
u64 vtype;

internal/include/uprobe.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
struct span_context psc;
2828

2929
// Common flow for uprobe return:
30-
// 1. Find consistend key for the current uprobe context
30+
// 1. Find consistent key for the current uprobe context
3131
// 2. Use the key to lookup for the uprobe context in the uprobe_context_map
3232
// 3. Update the end time of the found span
3333
// 4. Submit the constructed event to the agent code using perf buffer events_map

internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/bpf/probe.bpf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int uprobe_FetchMessage(struct pt_regs *ctx) {
146146
3. Blocking wait for message
147147
4. internal kafka code after blocking
148148
5. Return from FetchMessage
149-
Steps 2-4 are executed in a seperate goroutine from the one the user of the library.
149+
Steps 2-4 are executed in a separate goroutine from the one the user of the library.
150150
*/
151151
void *reader = get_argument(ctx, 1);
152152
void *context_data_ptr = get_Go_context(ctx, 3, 0, true);

internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/producer/bpf/probe.bpf.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static __always_inline int inject_kafka_header(void *message, struct kafka_heade
125125

126126
static __always_inline long collect_kafka_attributes(void *message, struct message_attributes_t *attrs, bool collect_topic) {
127127
if (collect_topic) {
128-
// Topic might be globaly set for a writer, or per message
128+
// Topic might be globally set for a writer, or per message
129129
get_go_string_from_user_ptr((void *)(message + message_topic_pos), attrs->topic, sizeof(attrs->topic));
130130
}
131131

@@ -188,7 +188,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
188188
// https://github.com/segmentio/kafka-go/blob/v0.2.3/message.go#L24C2-L24C6
189189
// 2. the time.Time struct is 24 bytes. This looks to be correct for all the reasnobaly latest versions according to
190190
// https://github.com/golang/go/blame/master/src/time/time.go#L135
191-
// In the future if more libraries will need to get structs sizes we probably want to have simillar
191+
// In the future if more libraries will need to get structs sizes we probably want to have similar
192192
// mechanism to the one we have for the offsets
193193
u16 msg_size = message_time_pos + 8 + 8 + 8;
194194
__builtin_memcpy(current_sc.TraceID, kafka_request->TraceID, TRACE_ID_SIZE);
@@ -198,7 +198,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
198198
if (i >= msgs_array_len) {
199199
break;
200200
}
201-
// Optionaly collect the topic, and always collect key
201+
// Optionally collect the topic, and always collect key
202202
collect_kafka_attributes(msg_ptr, &kafka_request->msgs[i], !global_topic);
203203
// Generate span id for each message
204204
generate_random_bytes(kafka_request->msgs[i].SpanID, SPAN_ID_SIZE);
@@ -216,7 +216,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
216216

217217

218218
bpf_map_update_elem(&kafka_events, &key, kafka_request, 0);
219-
// don't need to start tracking the span, as we don't have a context to propagate localy
219+
// don't need to start tracking the span, as we don't have a context to propagate locally
220220
return 0;
221221
}
222222

@@ -237,6 +237,6 @@ int uprobe_WriteMessages_Returns(struct pt_regs *ctx) {
237237

238238
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, kafka_request, sizeof(*kafka_request));
239239
bpf_map_delete_elem(&kafka_events, &key);
240-
// don't need to stop tracking the span, as we don't have a context to propagate localy
240+
// don't need to stop tracking the span, as we don't have a context to propagate locally
241241
return 0;
242242
}

internal/pkg/instrumentation/probe/probe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (i *Base[BPFObj, BPFEvent]) Close() error {
227227
// shutdown to avoid leaking system resources.
228228
type UprobeFunc[BPFObj any] func(symbol string, exec *link.Executable, target *process.TargetDetails, obj *BPFObj) ([]link.Link, error)
229229

230-
// Uprobe is an eBPF program that is attached in the entry point and/or the reutrn of a function.
230+
// Uprobe is an eBPF program that is attached in the entry point and/or the return of a function.
231231
type Uprobe[BPFObj any] struct {
232232
// Sym is the symbol name of the function to attach the eBPF program to.
233233
Sym string

internal/pkg/process/ptrace/ptrace_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func NewTracedProgram(pid int, logger logr.Logger) (*TracedProgram, error) {
7676
tidMap := make(map[int]bool)
7777
retryCount := make(map[int]int)
7878

79-
// iterate over the thread group, until it doens't change
79+
// iterate over the thread group, until it doesn't change
8080
//
8181
// we have tried several ways to ensure that we have stopped all the tasks:
8282
// 1. iterating over and over again to make sure all of them are tracee

internal/pkg/structfield/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func find[T any](slice *[]*T, f func(*T) bool) *T {
107107
// mergeSorted merges the two sorted slices slice0 and slice1 using the cmp
108108
// function to compare elements.
109109
//
110-
// The cmp function needs to return negative values when a<b, possitive values
110+
// The cmp function needs to return negative values when a<b, positive values
111111
// when a>b, and 0 when a==b.
112112
func mergeSorted[T any](slice0, slice1 []T, cmp func(a, b T) int) []T {
113113
merged := make([]T, 0, len(slice0)+len(slice1))

internal/test/e2e/gin/verify.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SCOPE="go.opentelemetry.io/auto/net/http"
3434
assert_equal "$result" '"/hello-gin"'
3535
}
3636

37-
@test "server :: includes hhttp.response.status_code attribute" {
37+
@test "server :: includes http.response.status_code attribute" {
3838
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"http.response.status_code\").value.intValue")
3939
assert_equal "$result" '"200"'
4040
}

internal/test/e2e/nethttp/verify.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SCOPE="go.opentelemetry.io/auto/net/http"
3434
assert_equal "$result" '"/hello/42"'
3535
}
3636

37-
@test "server :: includes hhttp.response.status_code attribute" {
37+
@test "server :: includes http.response.status_code attribute" {
3838
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"http.response.status_code\").value.intValue")
3939
assert_equal "$result" '"200"'
4040
}

internal/test/e2e/nethttp_custom/verify.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SCOPE="go.opentelemetry.io/auto/net/http"
3434
assert_equal "$result" '"/hello"'
3535
}
3636

37-
@test "server :: includes hhttp.response.status_code attribute" {
37+
@test "server :: includes http.response.status_code attribute" {
3838
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"http.response.status_code\").value.intValue")
3939
assert_equal "$result" '"200"'
4040
}

internal/tools/inspect/inspector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (i *Inspector) AddManifest(manifest Manifest) error {
8787

8888
goVer := manifest.Application.GoVerions
8989
if goVer == nil {
90-
// Passsing nil to newBuilder will mean the application is built with
90+
// Passing nil to newBuilder will mean the application is built with
9191
// the latest version of Go.
9292
b := newBuilder(i.log, i.client, nil)
9393
for _, ver := range manifest.Application.Versions {

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codespell==2.2.4

0 commit comments

Comments
 (0)