Skip to content

Instantly share code, notes, and snippets.

View ninjarobot's full-sized avatar

Dave Curylo ninjarobot

  • Microsoft @Azure
  • Atlanta, GA
View GitHub Profile
@ninjarobot
ninjarobot / dotnet.yaml
Last active April 7, 2024 13:13
Ansible playbook to install the .NET Core SDK on an Ubuntu server.
---
- hosts: all
tasks:
- name: Download MS product repository
get_url:
url: https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
dest: /tmp/packages-microsoft-prod.deb
- name: Install MS product repository
apt: deb=/tmp/packages-microsoft-prod.deb
become: true
@ninjarobot
ninjarobot / Fsharp.Async.Composition.fs
Created March 6, 2024 17:20
F# async composition
let sleepOnError fn =
async {
let! (res:Result<_,_>) = fn
return!
match res with
| Ok o -> async.Return (Ok o)
| Error e ->
async {
do! Async.Sleep 750
return Error e
@ninjarobot
ninjarobot / mkbundle-alpine-example.Dockerfile
Created June 19, 2017 17:41
A minimal Alpine image using a self-contained .NET executable built with mkbundle.
FROM alpine
RUN echo 'using System; \
namespace Program { \
public class MyClass { \
public static void Main(string[] args) { \
Console.WriteLine ("Hello from C#"); \
} \
} \
}' >> Program.cs
RUN apk add --virtual build-dependencies --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache mono mono-dev musl-dev binutils gcc && \
@ninjarobot
ninjarobot / tracing-intro-appinsights.md
Last active August 17, 2023 15:17
Correlated tracing in F# with Application Insights

Tracing with Application Insights

Application logging is ubiquitous and invaluable for troubleshooting. Structured logging enables you to log formatted messages and the data fields separately so that you can see the messages but also filter on the data fields. Tracing takes this a step further, where you can correlate many log entries together as you follow a trace of execution through an application. Traces also include additional information about the execution process, such as the sequence of calls to dependencies and how long any given call may take.

Application Insights lets you see all of this data correlated together in an application. You can search for an error log and then see in the execution flow that the log entry was added right after a failed call to another service. Or you can see that a certain web request is slower than others because it spends a lot of time on many redundant data access calls.

What about OpenTelemetry?

@ninjarobot
ninjarobot / Makefile
Created March 21, 2018 01:15
Makefile for Large .NET Project
HOME:=$(shell pwd)
NAME:=someLargeProject
DOCKER_REPO := my.internal.repo
DOCKER_REPO_DIR := mystuff
BUILD_CONTAINER := microsoft/dotnet:2-sdk
BASE_VERSION = 2.0
BUILD_NUMBER ?= 1
VERSION = ${BASE_VERSION}.${BUILD_NUMBER}
@ninjarobot
ninjarobot / AzureFunctionSecret.fs
Created January 5, 2018 20:58
Example of retrieving a secret from an F# Azure Function App
namespace AzurefnSecret
open Microsoft.Azure.KeyVault
open Microsoft.IdentityModel.Clients.ActiveDirectory
module Example =
let getSecret (appKeyDescription:string) (appKeyValue:string) (secretUrl:string) =
async {
use keyVault = new KeyVaultClient(fun authority resource (_:string) ->
async {
@ninjarobot
ninjarobot / JsonConfigSource.fs
Created January 20, 2021 23:52
Load a configuration source from a JSON string in F#
open Microsoft.Extensions.Configuration
/// Builds a configuration source from raw JSON.
let configSourceFromJson (json:string) : IConfigurationSource =
{ new IConfigurationSource with
member this.Build (builder:IConfigurationBuilder) =
{ new ConfigurationProvider() with
member this.Load() =
this.Data <- Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string,string>> json
} :> IConfigurationProvider
@ninjarobot
ninjarobot / Makefile
Last active September 6, 2022 05:49
Building nginx for macOS without homebrew
# default target so running 'make' by itself wll download and build nginx
build: nginx
cd nginx && ./configure --with-pcre=../pcre2 && make
nginx: pcre2
curl -O https://nginx.org/download/nginx-1.21.6.tar.gz
tar -xzvf nginx-*.tar.gz
mv nginx-*/ nginx
rm nginx-*.tar.gz
@ninjarobot
ninjarobot / system.drawing.colors.pdf
Created February 6, 2019 13:06
PDF Generated by F#
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ninjarobot
ninjarobot / strace-netcore.md
Last active May 24, 2022 19:22
Trace .NET Core Applications on Linux with `strace`

Trace .NET Core Applications on Linux with strace

Troubleshooting a running application can be difficult, usually it starts around checking log output and then following through the likely code paths to get an idea of where a failure may occur. In a development environment, you might attach a debugger a step through source, but troubleshooting isn't always that convenient. There are several helpful tools that can assist, but one that gives the most comprehensive view of a running application is strace. With strace you are able to see all of the system calls an application makes to get a detailed understanding of what is going on "under the hood" in order to troubleshoot an issue.

Take a simple "hello world" F# application, the kind you get from dotnet new console -lang F# -n strace-sample". Build it with dotnet build and then launch it with strace to get a trace of all the system calls in a file called trace.log(adjusting for your build output path if on a different framework vers