open-telemetry / opentelemetry.io

The OpenTelemetry website and documentation
https://opentelemetry.io
Creative Commons Attribution 4.0 International
491 stars 1.02k forks source link

Embed source code snippets from example repos #4276

Open zeitlinger opened 2 months ago

zeitlinger commented 2 months ago

I'd like to embed code snippets on the website

svrnm commented 2 months ago

Thanks @zeitlinger, just adding some of our slack conversation for context:

zeitlinger commented 2 months ago

Great - I'll just wait for more feedback on this issue :smile:

theletterf commented 2 months ago

I suggest moving this to Discussion.

chalin commented 2 months ago

As Severin pointed out in Slack, we have some tooling setup for code snippet refresh already, and it's tooling that has been used (for almost 9 years) and continues to be in use at Google, so it is well vetted; and the tools continue to be updated -- for the (current) canonical home of the tools, see https://github.com/dart-lang/site-shared/tree/main/packages. (Insider note that a JS rewrite of the tooling is in the works.)

I took a quick look at embedmd and I get the impression that it figures out which lines of code to bring in based on regexes. This is only one of the snippet extraction modes supported by the current tools, and generally not the preferred one given that it can be brittle. In the experiences I've had at Google maintaining websites with lots of code snippets, generally the best option (least brittle) is to add annotations to the source files for the purpose of delimiting code snippets. This makes it more obvious to developers when they update the code as to whether their changes might impact (and possibly break) code snippet extraction.

That being said, if you want to only use regexes with the current tooling you can.

I hope this helps.

FYI, I'm at half time this month and OOO all of next week. I'd be glad to work through a more complete example of the use of the current tooling, but it probably won't be until the end of the month. I'll do my best to answer any questions you might have as soon as I'm available.

svrnm commented 2 months ago

I suggest moving this to Discussion.

I think this is a very concrete ask (add code sync for java) with a binary answer (yes we do this, here is a PR, no we don't do this, close this issue), so a discussion might not be necessary.

on topic @chalin: would you be fine with @zeitlinger creating a PR for what he wants to accomplish using the current tooling (code_excerpter)?

chalin commented 2 months ago

@chalin: would you be fine with @zeitlinger creating a PR for what he wants to accomplish using the current tooling (code_excerpter)?

Yes, of course! 🙌🏻

There is one tweak that I want to make to the tooling so that it plays more nicely with Prettier, but the tools are usable as is.