From c9a387de087a5c092a7b3157e083ae462bc33d60 Mon Sep 17 00:00:00 2001
From: Cijo Thomas <cithomas@microsoft.com>
Date: Thu, 20 Oct 2022 10:05:56 -0700
Subject: [PATCH] Add MinMax to console and doc additions

---
 .vscode/settings.json                         |  1 +
 docs/metrics/customizing-the-sdk/Program.cs   |  2 ++
 docs/metrics/customizing-the-sdk/README.md    | 35 ++++++++++++++++++-
 .../CHANGELOG.md                              |  2 ++
 .../ConsoleMetricExporter.cs                  |  9 ++++-
 5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0fa40070760..0815e2dfa70 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -41,6 +41,7 @@
     "tracestate",
     "Tracestate",
     "triager",
+    "typeparam",
     "umesan",
     "unencrypted",
     "unvalidated",
diff --git a/docs/metrics/customizing-the-sdk/Program.cs b/docs/metrics/customizing-the-sdk/Program.cs
index 4172602fc2b..26dddcb2b7b 100644
--- a/docs/metrics/customizing-the-sdk/Program.cs
+++ b/docs/metrics/customizing-the-sdk/Program.cs
@@ -18,6 +18,7 @@
 using System.Diagnostics.Metrics;
 using OpenTelemetry;
 using OpenTelemetry.Metrics;
+using OpenTelemetry.Resources;
 
 namespace CustomizingTheSdk;
 
@@ -29,6 +30,7 @@ public class Program
     public static void Main()
     {
         using var meterProvider = Sdk.CreateMeterProviderBuilder()
+            .ConfigureResource(res => res.AddService("example-service"))
             .AddMeter(Meter1.Name)
             .AddMeter(Meter2.Name)
 
diff --git a/docs/metrics/customizing-the-sdk/README.md b/docs/metrics/customizing-the-sdk/README.md
index fbf5253a3a0..d8a6a73fa9f 100644
--- a/docs/metrics/customizing-the-sdk/README.md
+++ b/docs/metrics/customizing-the-sdk/README.md
@@ -427,4 +427,37 @@ Refer to the individual exporter docs to learn how to use them:
 
 ### Resource
 
-// TODO
+[Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md)
+is the immutable representation of the entity producing the telemetry. If no
+`Resource` is explicitly configured, the
+[default](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value)
+is to use a resource indicating this
+[Service](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service).
+The `ConfigureResource` method on `MeterProviderBuilder` can be used to set a
+configure the resource on the provider. When the provider is built, it
+automatically builds the final `Resource` from the configured `ResourceBuilder`.
+There can only be a single `Resource` associated with a
+provider. It is not possible to change the resource builder *after* the provider
+is built, by calling the `Build()` method on the `MeterProviderBuilder`.
+`ResourceBuilder` offers various methods to construct resource comprising of
+multiple attributes from various sources.
+
+The snippet below shows configuring the `Resource` associated with the provider.
+
+```csharp
+using OpenTelemetry;
+using OpenTelemetry.Resources;
+using OpenTelemetry.Metrics;
+
+using var meterProvider = Sdk.CreateMeterProviderBuilder()
+    .ConfigureResource(r => r.AddService("MyServiceName"))
+    .Build();
+```
+
+It is also possible to configure the `Resource` by using following
+environmental variables:
+
+| Environment variable       | Description                                        |
+| -------------------------- | -------------------------------------------------- |
+| `OTEL_RESOURCE_ATTRIBUTES` | Key-value pairs to be used as resource attributes. See the [Resource SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) for more details. |
+| `OTEL_SERVICE_NAME`        | Sets the value of the `service.name` resource attribute. If `service.name` is also provided in `OTEL_RESOURCE_ATTRIBUTES`, then `OTEL_SERVICE_NAME` takes precedence. |
diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md
index ae7089b8d61..1fc404b042e 100644
--- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md
@@ -10,6 +10,8 @@ LogRecordExporter to print full exception details instead of just Message, when
 using `ILogger` to log exception.
 ([#3784](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3784))
 
+Added support to print Histogram Min, Max in MetricExporter.
+
 ## 1.4.0-beta.2
 
 Released 2022-Oct-17
diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs
index f5833362d79..4826fedcd86 100644
--- a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs
+++ b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs
@@ -97,7 +97,14 @@ public override ExportResult Export(in Batch<Metric> batch)
                         var bucketsBuilder = new StringBuilder();
                         var sum = metricPoint.GetHistogramSum();
                         var count = metricPoint.GetHistogramCount();
-                        bucketsBuilder.Append($"Sum: {sum} Count: {count} \n");
+                        if (metricPoint.HasMinMax())
+                        {
+                            bucketsBuilder.Append($"Sum: {sum} Count: {count} Min: {metricPoint.GetHistogramMin()} Max: {metricPoint.GetHistogramMax()} \n");
+                        }
+                        else
+                        {
+                            bucketsBuilder.Append($"Sum: {sum} Count: {count} \n");
+                        }
 
                         bool isFirstIteration = true;
                         double previousExplicitBound = default;