Skip to content

Instantly share code, notes, and snippets.

View dasiths's full-sized avatar
💭
Breaking and fixing things for the CSE team @ Microsoft

Dasith Wijesiriwardena dasiths

💭
Breaking and fixing things for the CSE team @ Microsoft
View GitHub Profile
@dasiths
dasiths / promptflow-opentelemetry.py
Created May 3, 2024 14:46
Promptflow OpenTelemetry Custom Tracing Example
import logging
import threading
from typing import Dict, List
from azure.monitor.opentelemetry.exporter import (
AzureMonitorLogExporter,
AzureMonitorTraceExporter,
)
from flow_nodes.core.ConfigProvider import (
IsDevelopmentEnvironment,
@dasiths
dasiths / program.cs
Last active January 23, 2022 12:17
EF Core string to datetime/datetimeoffset value converter example with CAST SQL generation
using Microsoft.EntityFrameworkCore;
Console.WriteLine("Hello, World!");
using var x = new MyDbContext();
x.Database.EnsureCreated();
var paramValueDateTimeOffset = DateTimeOffset.Now.AddDays(-1);
var paramValueDateTime = DateTime.Now.AddDays(-1);
var query = x.CustomerLeases.Where(c => c.TextDateTime >= DateTimeOffset.Now
@dasiths
dasiths / TokenCredentialFactory.cs
Last active June 20, 2021 08:24
TokenCredential based on IConfiguration for .Azure Managed Identity in .NET
/*
More about Azure.Identity client library: https://devblogs.microsoft.com/azure-sdk/azure-identity-august-2020-ga/
Guidance on migrating from old Microsoft.Azure.Services.AppAuthentication library: https://docs.microsoft.com/en-us/dotnet/api/overview/azure/app-auth-migration
This is useful when the user account running the application locally in Visual Studio doesn't have permissions to the resources (i.e. Due to network restrictions/vpn or policy requirements).
We create a SP/AppRegistration and use that identity when running things locally.
TokenCredential is the base class for all credential types used for identity in Azure
like DefaultAzureCredential, ManagedIdentityCredential, EnvironmentCredential, ClientSecretCredential, VisualStudioCrdential etc (https://devblogs.microsoft.com/azure-sdk/azure-identity-august-2020-ga/#more-credential-types)
@dasiths
dasiths / trace.cs
Created May 14, 2021 13:58
Tracing + Telemetry using .NET and Application Insights
// Reading
// https://tsuyoshiushio.medium.com/correlation-with-activity-with-application-insights-1-overview-753a48a645fb
// https://tsuyoshiushio.medium.com/correlation-with-activity-with-application-insights-2-activity-deep-dive-2a4147919659
// https://medium.com/prospa-engineering/implementing-distributed-tracing-with-azures-application-insights-5a09cc1c200c
var activity = new Activity("Call to CosmosDB");
// activity.SetParentId("correlation id from request")
//RequestTelemetry for Request, DependencyTelemtry for Dependencies
using var operation = telemetryClient.StartOperation<DependencyTelemetry>(activity);