Skip to content

Commit b1712ad

Browse files
authored
[CI] Support code-snippet extraction and docs-updating (open-telemetry#3948)
1 parent 26c88f1 commit b1712ad

File tree

12 files changed

+69
-1
lines changed

12 files changed

+69
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ assets/jsconfig.json
2626

2727
# Webstorm
2828
/.idea/**
29+
30+
.dart_tool
31+
pubspec.lock

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@
2323
path = content-modules/opamp-spec
2424
url = https://github.com/open-telemetry/opamp-spec
2525
opamp-pin = v0.8.0-5-g0360da8
26+
[submodule "content-modules/opentelemetry-go"]
27+
path = content-modules/opentelemetry-go
28+
url = https://github.com/open-telemetry/opentelemetry-go
29+
go-pin = v1.23.0-rc.1-31-geabcef4c2

content-modules/opentelemetry-go

Submodule opentelemetry-go added at eabcef4

content/en/docs/languages/go/getting-started.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ weight: 10
55
cSpell:ignore: chan fatalln funcs intn itoa khtml otelhttp rolldice stdouttrace strconv
66
---
77

8+
<!-- markdownlint-disable blanks-around-fences -->
9+
<?code-excerpt path-base="examples/go/dice"?>
10+
811
This page will show you how to get started with OpenTelemetry in Go.
912

1013
You will learn how you can instrument a simple application manually, in such a
@@ -121,6 +124,8 @@ application that exports telemetry.
121124

122125
Create `otel.go` with OpenTelemetry SDK bootstrapping code:
123126

127+
<!-- prettier-ignore-start -->
128+
<?code-excerpt "otel.go" from="package main"?>
124129
```go
125130
package main
126131

@@ -220,6 +225,7 @@ func newMeterProvider() (*metric.MeterProvider, error) {
220225
return meterProvider, nil
221226
}
222227
```
228+
<!-- prettier-ignore-end -->
223229

224230
If you're only using tracing or metrics, you can omit the code the corresponding
225231
TracerProvider or MeterProvider initialization code.
@@ -232,6 +238,8 @@ server.
232238
Modify `main.go` to include code that sets up OpenTelemetry SDK and instruments
233239
the HTTP server using the `otelhttp` instrumentation library:
234240

241+
<!-- prettier-ignore-start -->
242+
<?code-excerpt "main.go" from="package main"?>
235243
```go
236244
package main
237245

@@ -317,6 +325,7 @@ func newHTTPHandler() http.Handler {
317325
return handler
318326
}
319327
```
328+
<!-- prettier-ignore-end -->
320329

321330
### Add Custom Instrumentation
322331

@@ -327,6 +336,8 @@ your application. For that you'll need to write some custom
327336

328337
Modify `rolldice.go` to include custom instrumentation using OpenTelemetry API:
329338

339+
<!-- prettier-ignore-start -->
340+
<?code-excerpt "rolldice.go" from="package main"?>
330341
```go
331342
package main
332343

@@ -364,7 +375,6 @@ func rolldice(w http.ResponseWriter, r *http.Request) {
364375

365376
roll := 1 + rand.Intn(6)
366377

367-
// Add the custom attribute to the span and counter.
368378
rollValueAttr := attribute.Int("roll.value", roll)
369379
span.SetAttributes(rollValueAttr)
370380
rollCnt.Add(ctx, 1, metric.WithAttributes(rollValueAttr))
@@ -375,6 +385,7 @@ func rolldice(w http.ResponseWriter, r *http.Request) {
375385
}
376386
}
377387
```
388+
<!-- prettier-ignore-end -->
378389

379390
Note that if you're only using tracing or metrics, you can omit the
380391
corresponding code that instruments the other telemetry type.

examples/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Examples
2+
3+
The files in this folder are used to extract code snippets that are used in the
4+
docs.

examples/go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../content-modules/opentelemetry-go/example

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"check:text": "npm run _check:text -- ",
4444
"check": "npm run seq -- $(npm run -s _list:check:*)",
4545
"clean": "make clean",
46+
"code-excerpts": "rm -Rf tmp/excerpts/* && npm run seq -- code-excerpts:get code-excerpts:update-docs",
47+
"code-excerpts:get": "cd tools && dart run build_runner build --delete-conflicting-outputs --output ../tmp/excerpts",
48+
"code-excerpts:update-docs": "cd tools && dart run code_excerpt_updater --fragment-dir-path ../tmp/excerpts --src-dir-path examples --yaml --write-in-place content",
4649
"cp:spec": "./scripts/content-modules/cp-pages.sh",
4750
"diff:check": "npm run _diff:check || (echo; echo 'WARNING: the files above have not been committed'; echo)",
4851
"diff:fail": "npm run _diff:check || (echo; echo 'ERROR: the files above have changed. Locally rerun `npm run test-and-fix` and commit changes'; echo; exit 1)",

tools/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tools for handling code excerpts
2+
3+
This directory contains the tooling, config, and data sources for managing code
4+
excerpts. This functionality is currently experimental, and used only by site
5+
maintainers.
6+
7+
## Dependencies
8+
9+
- **Dart**: for installation instructions, see [Get the Dart SDK].
10+
11+
[Get the Dart SDK]: https://dart.dev/get-dart

tools/build.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
targets:
2+
$default:
3+
sources:
4+
include:
5+
- examples/**
6+
# The following are included to avoid "required resources" tool warnings:
7+
- $package$
8+
- lib/$lib$
9+
# exclude: ['**/.*/**']
10+
builders:
11+
code_excerpter|code_excerpter:
12+
enabled: true

tools/content/go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../content/en/docs/languages/go

tools/examples

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../examples

tools/pubspec.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: otel_io_excerpts
2+
publish_to: none
3+
4+
environment:
5+
sdk: ^3.2.0
6+
7+
dev_dependencies:
8+
build_runner: ^2.4.6
9+
code_excerpter:
10+
git:
11+
url: https://github.com/chalin/site-shared
12+
path: packages/code_excerpter
13+
code_excerpt_updater:
14+
git:
15+
url: https://github.com/chalin/site-shared
16+
path: packages/code_excerpt_updater

0 commit comments

Comments
 (0)