-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CosmosDb support + tests Prior PR: #1239 * Create test_resources.tf
- Loading branch information
1 parent
2368354
commit 243b7f8
Showing
14 changed files
with
994 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "=2.46.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
# configuration is sourced from the following environment variables: | ||
# ARM_CLIENT_ID | ||
# ARM_CLIENT_SECRET | ||
# ARM_SUBSCRIPTION_ID | ||
# ARM_TENANT_ID | ||
# | ||
# See https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret | ||
# for creating a Service Principal and Client Secret | ||
data "azurerm_client_config" "current" { | ||
} | ||
|
||
variable "resource_group" { | ||
type = string | ||
description = "The name of the resource group to create" | ||
} | ||
|
||
variable "location" { | ||
type = string | ||
description = "The Azure location in which to deploy resources" | ||
default = "westus" | ||
} | ||
|
||
variable "cosmos_db_account_name" { | ||
type = string | ||
description = "The name of the cosmos db account to create" | ||
} | ||
|
||
resource "azurerm_resource_group" "cosmos_db_resource_group" { | ||
name = var.resource_group | ||
location = var.location | ||
} | ||
|
||
resource "azurerm_cosmosdb_account" "cosmos_db_account" { | ||
name = var.cosmos_db_account_name | ||
location = azurerm_resource_group.cosmos_db_resource_group.location | ||
resource_group_name = azurerm_resource_group.cosmos_db_resource_group.name | ||
offer_type = "Standard" | ||
kind = "GlobalDocumentDB" | ||
enable_automatic_failover = false | ||
|
||
capabilities { | ||
name = "EnableAggregationPipeline" | ||
} | ||
|
||
capabilities { | ||
name = "mongoEnableDocLevelTTL" | ||
} | ||
|
||
capabilities { | ||
name = "MongoDBv3.4" | ||
} | ||
|
||
consistency_policy { | ||
consistency_level = "Strong" | ||
} | ||
|
||
geo_location { | ||
location = azurerm_resource_group.cosmos_db_resource_group.location | ||
failover_priority = 0 | ||
} | ||
} | ||
|
||
output "endpoint" { | ||
value = azurerm_cosmosdb_account.cosmos_db_account.endpoint | ||
} | ||
|
||
output "primary_master_key" { | ||
value = azurerm_cosmosdb_account.cosmos_db_account.primary_master_key | ||
sensitive = true | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Elastic.Apm.Azure.CosmosDb/AzureCosmosDbDiagnosticsSubscriber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to Elasticsearch B.V under | ||
// one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using Elastic.Apm.DiagnosticSource; | ||
|
||
namespace Elastic.Apm.Azure.CosmosDb | ||
{ | ||
/// <summary> | ||
/// Subscribes to HTTP requests from Microsoft.Azure.Cosmos, Microsoft.Azure.DocumentDb, and Microsoft.Azure.DocumentDb.Core. | ||
/// </summary> | ||
public class AzureCosmosDbDiagnosticsSubscriber : IDiagnosticsSubscriber | ||
{ | ||
/// <summary> | ||
/// Subscribes to HTTP requests | ||
/// </summary> | ||
public IDisposable Subscribe(IApmAgent agent) | ||
{ | ||
if (agent is ApmAgent realAgent) | ||
{ | ||
realAgent.HttpTraceConfiguration.AddTracer(new AzureCosmosDbTracer()); | ||
|
||
if (!realAgent.HttpTraceConfiguration.Subscribed) | ||
realAgent.Subscribe(new HttpDiagnosticsSubscriber(false)); | ||
} | ||
|
||
return EmptyDisposable.Instance; | ||
} | ||
} | ||
} |
Oops, something went wrong.