copy of OpenCensus at 0474607a16282252697f989113d68bdf71959070

This commit is contained in:
Sergey Kanzhelev 2019-05-08 12:32:06 -07:00
parent ab531691cb
commit 0c01f9f0aa
494 changed files with 51020 additions and 2 deletions

330
.gitignore vendored Normal file
View File

@ -0,0 +1,330 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/

28
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/test/OpenCensus.Collector.Dependencies.Tests/bin/Debug/netcoreapp2.0/OpenCensus.Collector.Dependencies.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/test/OpenCensus.Collector.Dependencies.Tests",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"rewrap.wrappingColumn": 79,
"files.associations": {
".vsts/*.yml": "azure-pipelines"
}
}

17
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet build",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

60
.vsts/ci-build.yml Normal file
View File

@ -0,0 +1,60 @@
# CI build. No publioshing of artifacts
variables:
DotNetVersion: "2.2.101"
pr: [ 'master', 'develop' ]
jobs:
- job: Windows
pool: Hosted VS2017
steps:
- task: DotNetCoreInstaller@0
displayName: force use of desired dotnet version
inputs:
version: $(DotNetVersion)
# "restore" is run automatically by "build"
- task: DotNetCoreCLI@2
displayName: build solution (Release)
inputs:
command: "build"
projects: "OpenCensus.proj"
arguments: "--configuration Release"
# consider switch to https://docs.microsoft.com/vsts/pipelines/tasks/test/vstest?view=vsts
- task: DotNetCoreCLI@2
displayName: test
inputs:
command: "test"
projects: "test/**/*.Tests.csproj"
arguments: "--configuration Release"
- task: PublishTestResults@2
- job: Linux
pool: Hosted Ubuntu 1604
steps:
- task: DotNetCoreInstaller@0
displayName: force use of desired dotnet version
inputs:
version: $(DotNetVersion)
# "restore" is run automatically by "build"
- task: DotNetCoreCLI@2
displayName: build
inputs:
command: "build"
projects: "OpenCensus.proj"
arguments: "--configuration Release"
- task: DotNetCoreCLI@2
displayName: test
inputs:
command: "test"
projects: "test/**/*.Tests.csproj"
arguments: "--configuration Release"
- task: PublishTestResults@2

51
.vsts/ci-myget-update.yml Normal file
View File

@ -0,0 +1,51 @@
# CI build with the upload to MyGet
variables:
DotNetVersion: "2.2.101"
trigger:
branches:
include:
- master
- develop
queue: Hosted VS2017
steps:
- task: DotNetCoreInstaller@0
displayName: force use of desired dotnet version
inputs:
version: $(DotNetVersion)
# "build" and "restore" are run by "pack".
- task: DotNetCoreCLI@2
displayName: pack solution with symbols (Release)
inputs:
command: "pack"
projects: "OpenCensus.proj"
configuration: 'Release'
packDirectory: '$(build.artifactStagingDirectory)'
buildProperties: "SymbolPackageFormat=snupkg"
- task: DotNetCoreCLI@2
displayName: test
inputs:
command: "test"
projects: "test/**/*.Tests.csproj"
arguments: "--configuration Release"
- task: PublishTestResults@2
- task: NuGetCommand@2
displayName: 'Publish nugets to MyGet'
inputs:
command: push
nuGetFeedType: external
publishFeedCredentials: 'myget-open-census'
# this task is required as symbols packages needs to be published manually.
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: "$(build.artifactstagingdirectory)"
ArtifactName: "drop"
ArtifactType: "Container"

40
CHANGELOG.md Normal file
View File

@ -0,0 +1,40 @@
# Changelog
Please update changelog as part of any significant pull request. Place short
description of your change into "Unreleased" section. As part of release
process content of "Unreleased" section content will generate release notes for
the release.
## Unreleased
- API improvements - use C# native classes to measure time.
- OpenCensus.Collectors.AspNetCore: Allow to supply custom sampler based on request properties using custom code. For instance filter out telemetry from specific path.
- OpenCensus.Collectors.Dependencies: Allow to supply custom sampler based on request properties using custom code. By default, filter out calls to Zipkin REST endpoint from the exporter.
## 0.1.0-alpha-42253
Release [01/18/2019](https://github.com/census-instrumentation/opencensus-csharp/releases/tag/0.1.0-alpha-42253).
- Application Insights exporter improvements - now understands http attributes
and process links, annotations and messages.
- ASP.NET Core collector now uses `http.route` for the span name.
- Initial implementation of Resource Specification.
- Plug in to collect Redis calls made using StackExchange.Redis package.
- Object of type `ISpanData` can be created using only Abstractions package.
- Number of minor APIs adjustments.
## 0.1.0-alpha-33381
Released
[12/18/2018](https://github.com/census-instrumentation/opencensus-csharp/releases/tag/0.1.0-alpha-33381).
- Collectors for ASP.NET Core and .NET Core HttpClient.
- Initial version of Ocagent exporter implemented.
- Initial version of StackDriver exporter implemented.
- Support double attributes according to the [spec
change](https://github.com/census-instrumentation/opencensus-specs/issues/172).
- Initial implementation of Prometheus exporter.
- Initial version of Application Insights exporter implemented.
- Zipkin exporter implemented.
- Initial version of SDK published. It is based on contribution from Pivotal
[from](https://github.com/SteeltoeOSS/Management/tree/dev/src/Steeltoe.Management.OpenCensus).

50
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,50 @@
# Contributing
## Report a bug or requesting feature
Reporting bug is an important contribution. Please make sure to include:
- expected and actual behavior.
- dotnet version that application is compiled on and running with (it may be
different - for instance target framework was set to .NET 4.6 for
compilaiton, but applicaiton is running on .NET 4.7.3).
- exception call stack and other artifacts.
- if possible - reporo application and steps to reproduce.
## How to contribute
### Before started
In order to protect both you and ourselves, you will need to sign the
[Contributor License Agreement](https://cla.developers.google.com/clas).
### Build
You can use Visual Studio 2017 or VS code to contribute. Just open root folder
or `OpenCensus.sln` in your editor and follow normal development process.
To build from command line you need `dotnet` version `2.0+`.
``` sh
dotnet build OpenCensus.sln
```
### Test
You can use Visual Studio 2017 or VS code to test your contribution. Open root
folder or `OpenCensus.sln` in your editor and follow normal development
process.
To test from command line you need `dotnet` version `2.0+`.
``` sh
dotnet test OpenCensus.sln
```
### Proposing changes
Create a Pull Request with your changes. Please add any user-visible changes to
`CHANGELOG.md`. The continuous integration build will run the tests and static
analysis. It will also check that the pull request branch has no merge commits.
When the changes are accepted, they will be merged or cherry-picked by an
OpenCensus repository maintainers.

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

8
NuGet.config Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources />
</configuration>

19
OpenCensus.proj Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project=".\build\Common.prod.props" />
<ItemGroup>
<Solution Include="OpenCensus.sln" />
</ItemGroup>
<!-- The only need for this file is to synchronize the PreReleaseVersion -->
<Target Name="Build">
<MSBuild Projects="@(Solution)" Targets="Restore;Build" ContinueOnError="ErrorAndStop" Properties="PreReleaseVersion=$(PreReleaseVersion)"/>
</Target>
<Target Name="Pack">
<MSBuild Projects="@(Solution)" Targets="Restore;Build;Pack" ContinueOnError="ErrorAndStop" Properties="PreReleaseVersion=$(PreReleaseVersion)"/>
</Target>
</Project>

158
OpenCensus.sln Normal file
View File

@ -0,0 +1,158 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus", "src\OpenCensus\OpenCensus.csproj", "{AE3E3DF5-4083-4C6E-A840-8271B0ACDE7E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Tests", "test\OpenCensus.Tests\OpenCensus.Tests.csproj", "{CC62B3C1-5875-4986-A7F6-C4B26E42B0A1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B7408D66-487A-40E1-BDB7-BC17BD28F721}"
ProjectSection(SolutionItems) = preProject
CHANGELOG.md = CHANGELOG.md
CONTRIBUTING.md = CONTRIBUTING.md
NuGet.config = NuGet.config
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E-03FA-4FFF-89A5-C51F107623FD}"
ProjectSection(SolutionItems) = preProject
build\Common.prod.props = build\Common.prod.props
build\Common.test.props = build\Common.test.props
build\debug.snk = build\debug.snk
build\OpenCensus.prod.loose.ruleset = build\OpenCensus.prod.loose.ruleset
build\OpenCensus.prod.ruleset = build\OpenCensus.prod.ruleset
build\OpenCensus.test.ruleset = build\OpenCensus.test.ruleset
build\stylecop.json = build\stylecop.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.Zipkin", "src\OpenCensus.Exporter.Zipkin\OpenCensus.Exporter.Zipkin.csproj", "{7EDAE7FA-B44E-42CA-80FA-7DF2FAA2C5DD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".vsts", ".vsts", "{61188153-47FB-4567-AC9B-79B2435853EB}"
ProjectSection(SolutionItems) = preProject
.vsts\ci-build.yml = .vsts\ci-build.yml
.vsts\ci-myget-update.yml = .vsts\ci-myget-update.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.ApplicationInsights", "src\OpenCensus.Exporter.ApplicationInsights\OpenCensus.Exporter.ApplicationInsights.csproj", "{4493F5D9-874E-4FBF-B2F3-37890BD910E0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.Stackdriver", "src\OpenCensus.Exporter.Stackdriver\OpenCensus.Exporter.Stackdriver.csproj", "{DE1B4783-C01F-4672-A6EB-695F1717105B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples", "src\Samples\Samples.csproj", "{C58393EB-32E2-4AC6-9170-697B36306E15}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Abstractions", "src\OpenCensus.Abstractions\OpenCensus.Abstractions.csproj", "{99F8A331-05E9-45A5-89BA-4C54E825E5B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.Prometheus", "src\OpenCensus.Exporter.Prometheus\OpenCensus.Exporter.Prometheus.csproj", "{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Collector.Dependencies", "src\OpenCensus.Collector.Dependencies\OpenCensus.Collector.Dependencies.csproj", "{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Collector.Dependencies.Tests", "test\OpenCensus.Collector.Dependencies.Tests\OpenCensus.Collector.Dependencies.Tests.csproj", "{56E2647A-B814-4BAC-B854-BEA0051B5F2E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Collector.AspNetCore", "src\OpenCensus.Collector.AspNetCore\OpenCensus.Collector.AspNetCore.csproj", "{752D2182-A351-41D8-99EE-DD363D7D5B43}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Collector.AspNetCore.Tests", "test\OpenCensus.Collector.AspNetCore.Tests\OpenCensus.Collector.AspNetCore.Tests.csproj", "{2A47F6A8-63E5-4237-8046-94CAF321E797}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testdata", "testdata", "{77C7929A-2EED-4AA6-8705-B5C443C8AA0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore.2.0", "test\TestApp.AspNetCore.2.0\TestApp.AspNetCore.2.0.csproj", "{F2F81E76-6A0E-466B-B673-EBBF1A9ED075}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.Ocagent", "src\OpenCensus.Exporter.Ocagent\OpenCensus.Exporter.Ocagent.csproj", "{56B0ED25-8A14-4AA2-B59D-FAAFCBACDD4A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.Stackdriver.Tests", "test\OpenCensus.Exporter.Stackdriver.Tests\OpenCensus.Exporter.Stackdriver.Tests.csproj", "{6875032B-DFDC-4CDE-A283-37CA7F99926A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.ApplicationInsights.Tests", "test\OpenCensus.Exporter.ApplicationInsights.Tests\OpenCensus.Exporter.ApplicationInsights.Tests.csproj", "{1FA1F509-7722-48E3-9A35-16CBB6774957}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Collector.StackExchangeRedis", "src\OpenCensus.Collector.StackExchangeRedis\OpenCensus.Collector.StackExchangeRedis.csproj", "{6B681D72-D68A-44CC-8C75-53B9A322E6EC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Collector.StackExchangeRedis.Tests", "test\OpenCensus.Collector.StackExchangeRedis.Tests\OpenCensus.Collector.StackExchangeRedis.Tests.csproj", "{CA98AF29-0852-4ADD-A66B-7E96266EE7B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE3E3DF5-4083-4C6E-A840-8271B0ACDE7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE3E3DF5-4083-4C6E-A840-8271B0ACDE7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE3E3DF5-4083-4C6E-A840-8271B0ACDE7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE3E3DF5-4083-4C6E-A840-8271B0ACDE7E}.Release|Any CPU.Build.0 = Release|Any CPU
{CC62B3C1-5875-4986-A7F6-C4B26E42B0A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC62B3C1-5875-4986-A7F6-C4B26E42B0A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC62B3C1-5875-4986-A7F6-C4B26E42B0A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC62B3C1-5875-4986-A7F6-C4B26E42B0A1}.Release|Any CPU.Build.0 = Release|Any CPU
{7EDAE7FA-B44E-42CA-80FA-7DF2FAA2C5DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EDAE7FA-B44E-42CA-80FA-7DF2FAA2C5DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EDAE7FA-B44E-42CA-80FA-7DF2FAA2C5DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EDAE7FA-B44E-42CA-80FA-7DF2FAA2C5DD}.Release|Any CPU.Build.0 = Release|Any CPU
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Release|Any CPU.Build.0 = Release|Any CPU
{DE1B4783-C01F-4672-A6EB-695F1717105B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE1B4783-C01F-4672-A6EB-695F1717105B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE1B4783-C01F-4672-A6EB-695F1717105B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE1B4783-C01F-4672-A6EB-695F1717105B}.Release|Any CPU.Build.0 = Release|Any CPU
{C58393EB-32E2-4AC6-9170-697B36306E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C58393EB-32E2-4AC6-9170-697B36306E15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C58393EB-32E2-4AC6-9170-697B36306E15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C58393EB-32E2-4AC6-9170-697B36306E15}.Release|Any CPU.Build.0 = Release|Any CPU
{99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Release|Any CPU.Build.0 = Release|Any CPU
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Release|Any CPU.Build.0 = Release|Any CPU
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Release|Any CPU.Build.0 = Release|Any CPU
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Release|Any CPU.Build.0 = Release|Any CPU
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Release|Any CPU.Build.0 = Release|Any CPU
{2A47F6A8-63E5-4237-8046-94CAF321E797}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A47F6A8-63E5-4237-8046-94CAF321E797}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A47F6A8-63E5-4237-8046-94CAF321E797}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A47F6A8-63E5-4237-8046-94CAF321E797}.Release|Any CPU.Build.0 = Release|Any CPU
{F2F81E76-6A0E-466B-B673-EBBF1A9ED075}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2F81E76-6A0E-466B-B673-EBBF1A9ED075}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2F81E76-6A0E-466B-B673-EBBF1A9ED075}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2F81E76-6A0E-466B-B673-EBBF1A9ED075}.Release|Any CPU.Build.0 = Release|Any CPU
{56B0ED25-8A14-4AA2-B59D-FAAFCBACDD4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56B0ED25-8A14-4AA2-B59D-FAAFCBACDD4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56B0ED25-8A14-4AA2-B59D-FAAFCBACDD4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56B0ED25-8A14-4AA2-B59D-FAAFCBACDD4A}.Release|Any CPU.Build.0 = Release|Any CPU
{6875032B-DFDC-4CDE-A283-37CA7F99926A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6875032B-DFDC-4CDE-A283-37CA7F99926A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6875032B-DFDC-4CDE-A283-37CA7F99926A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6875032B-DFDC-4CDE-A283-37CA7F99926A}.Release|Any CPU.Build.0 = Release|Any CPU
{1FA1F509-7722-48E3-9A35-16CBB6774957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FA1F509-7722-48E3-9A35-16CBB6774957}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FA1F509-7722-48E3-9A35-16CBB6774957}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FA1F509-7722-48E3-9A35-16CBB6774957}.Release|Any CPU.Build.0 = Release|Any CPU
{6B681D72-D68A-44CC-8C75-53B9A322E6EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B681D72-D68A-44CC-8C75-53B9A322E6EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B681D72-D68A-44CC-8C75-53B9A322E6EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B681D72-D68A-44CC-8C75-53B9A322E6EC}.Release|Any CPU.Build.0 = Release|Any CPU
{CA98AF29-0852-4ADD-A66B-7E96266EE7B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA98AF29-0852-4ADD-A66B-7E96266EE7B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA98AF29-0852-4ADD-A66B-7E96266EE7B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA98AF29-0852-4ADD-A66B-7E96266EE7B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7CB2F02E-03FA-4FFF-89A5-C51F107623FD} = {61188153-47FB-4567-AC9B-79B2435853EB}
{F2F81E76-6A0E-466B-B673-EBBF1A9ED075} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}
EndGlobalSection
EndGlobal

316
README.md
View File

@ -1,3 +1,315 @@
# OpenTelemetry .NET SDK
# OpenCensus .NET SDK - distributed tracing and stats collection framework
This repository contains .NET version of OpenTelemetry SDK.
[![Gitter chat][gitter-image]][gitter-url]
[![Build Status](https://opencensus.visualstudio.com/continuous-integration/_apis/build/status/ci-myget-update.yml)](https://opencensus.visualstudio.com/continuous-integration/_build/latest?definitionId=3)
OpenCensus is a toolkit for collecting application performance and behavior
data. It currently includes 3 APIs: stats, tracing and tags.
The library is in [Beta](#versioning) stage and APIs are expected to be mostly
stable. The library is expected to move to [GA](#versioning) stage after v1.0.0
major release.
Please join [gitter](https://gitter.im/census-instrumentation/Lobby) for help
or feedback on this project.
We encourage contributions. Use tags [up-for-grabs][up-for-grabs-issues] and
[good first issue][good-first-issues] to get started with the project. Follow
[CONTRIBUTING](CONTRIBUTING.md) guide to report issues or submit a proposal.
## Packages
### API and implementation
| Package | MyGet (CI) | NuGet (releases) |
| ----------------------- | ---------------- | -----------------|
| OpenCensus | [![MyGet Nightly][opencensus-myget-image]][opencensus-myget-url] | [![NuGet Release][opencensus-nuget-image]][opencensus-nuget-url] |
| OpenCensus.Abstractions | [![MyGet Nightly][opencensus-abs-myget-image]][opencensus-abs-myget-url] | [![NuGet Release][opencensus-abs-nuget-image]][opencensus-abs-nuget-url] |
### Data Collectors
| Package | MyGet (CI) | NuGet (releases) |
| ----------------------- | ---------------- | -----------------|
| Asp.Net Core | [![MyGet Nightly][opencensus-collect-aspnetcore-myget-image]][opencensus-collect-aspnetcore-myget-url] | [![NuGet Release][opencensus-collect-aspnetcore-nuget-image]][opencensus-collect-aspnetcore-nuget-url] |
| .Net Core HttpClient | [![MyGet Nightly][opencensus-collect-deps-myget-image]][opencensus-collect-deps-myget-url] | [![NuGet Release][opencensus-collect-deps-nuget-image]][opencensus-collect-deps-nuget-url] |
| StackExchange.Redis | [![MyGet Nightly][opencensus-collect-stackexchange-redis-myget-image]][opencensus-collect-stackexchange-redis-myget-url] | [![NuGet Release][opencensus-collect-stackexchange-redis-nuget-image]][opencensus-collect-stackexchange-redis-nuget-url]|
### Exporters Packages
| Package | MyGet (CI) | NuGet (releases) |
| ----------------------- | ---------------- | -----------------|
| Zipkin | [![MyGet Nightly][opencensus-exporter-zipkin-myget-image]][opencensus-exporter-zipkin-myget-url] | [![NuGet release][opencensus-exporter-zipkin-nuget-image]][opencensus-exporter-zipkin-nuget-url] |
| Prometheus | [![MyGet Nightly][opencensus-exporter-prom-myget-image]][opencensus-exporter-prom-myget-url] | [![NuGet release][opencensus-exporter-prom-nuget-image]][opencensus-exporter-prom-nuget-url] |
| Application Insights | [![MyGet Nightly][opencensus-exporter-ai-myget-image]][opencensus-exporter-ai-myget-url] | [![NuGet release][opencensus-exporter-ai-nuget-image]][opencensus-exporter-ai-nuget-url] |
| Stackdriver | [![MyGet Nightly][opencensus-exporter-stackdriver-myget-image]][opencensus-exporter-stackdriver-myget-url] | [![NuGet release][opencensus-exporter-stackdriver-nuget-image]][opencensus-exporter-stackdriver-nuget-url] |
## OpenCensus QuickStart: collecting data
You can use Open Census API to instrument code and report data. Or use one of
automatic data collection modules.
### Using ASP.NET Core incoming requests collector
Incoming requests of ASP.NET Core app can be automatically tracked.
1. Install packages to your project:
[OpenCensus][opencensus-nuget-url]
[OpenCensus.Collector.AspNetCore][opencensus-collect-aspnetcore-nuget-url]
2. Make sure `ITracer`, `ISampler`, and `IPropagationComponent` registered in DI.
``` csharp
services.AddSingleton<ITracer>(Tracing.Tracer);
services.AddSingleton<ISampler>(Samplers.AlwaysSample);
services.AddSingleton<IPropagationComponent>(new DefaultPropagationComponent());
```
3. Configure data collection singletons in ConfigureServices method:
``` csharp
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddSingleton<RequestsCollectorOptions>(new RequestsCollectorOptions());
services.AddSingleton<RequestsCollector>();
```
4. Initialize data collection by instantiating singleton in Configure method
``` csharp
public void Configure(IApplicationBuilder app, /*... other arguments*/ )
{
// ...
var collector = app.ApplicationServices.GetService<RequestsCollector>();
```
### Using Dependencies collector
Outgoing http calls made by .NET Core `HttpClient` can be automatically tracked.
1. Install package to your project:
[OpenCensus.Collector.Dependencies][opencensus-collect-deps-nuget-url]
2. Make sure `ITracer`, `ISampler`, and `IPropagationComponent` registered in DI.
``` csharp
services.AddSingleton<ITracer>(Tracing.Tracer);
services.AddSingleton<ISampler>(Samplers.AlwaysSample);
services.AddSingleton<IPropagationComponent>(new DefaultPropagationComponent());
```
3. Configure data collection singletons in ConfigureServices method:
``` csharp
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddSingleton<DependenciesCollectorOptions>(new DependenciesCollectorOptions());
services.AddSingleton<DependenciesCollector>();
```
4. Initiate data collection by instantiating singleton in Configure method
``` csharp
public void Configure(IApplicationBuilder app, /*... other arguments*/ )
{
// ...
var depCollector = app.ApplicationServices.GetService<DependenciesCollector>();
```
### Using StackExchange.Redis collector
Outgoing http calls to Redis made usign StackExchange.Redis library can be automatically tracked.
1. Install package to your project:
[OpenCensus.Collector.StackExchangeRedis][opencensus-collect-stackexchange-redis-nuget-url]
2. Make sure `ITracer`, `ISampler`, and `IExportComponent` registered in DI.
``` csharp
services.AddSingleton<ITracer>(Tracing.Tracer);
services.AddSingleton<ISampler>(Samplers.AlwaysSample);
services.AddSingleton<IExportComponent>(Tracing.ExportComponent);
```
3. Configure data collection singletons in ConfigureServices method:
``` csharp
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddSingleton<StackExchangeRedisCallsCollectorOptions>(new StackExchangeRedisCallsCollectorOptions());
services.AddSingleton<StackExchangeRedisCallsCollector>();
```
4. Initiate data collection by instantiating singleton in Configure method
``` csharp
public void Configure(IApplicationBuilder app, /*... other arguments*/ )
{
// ...
var redisCollector = app.ApplicationServices.GetService<StackExchangeRedisCallsCollector>();
// use collector to configure the profiler
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("localhost:6379");
connection.RegisterProfiler(redisCollector.GetProfilerSessionsFactory());
```
## OpenCensus QuickStart: exporting data
### Using Zipkin exporter
Configure Zipkin exporter to see traces in Zipkin UI.
1. Get Zipkin using [getting started guide][zipkin-get-started].
2. Start `ZipkinTraceExporter` as below:
3. See [sample][zipkin-sample] for example use.
``` csharp
var exporter = new ZipkinTraceExporter(
new ZipkinTraceExporterOptions() {
Endpoint = new Uri("https://<zipkin-server:9411>/api/v2/spans"),
ServiceName = typeof(Program).Assembly.GetName().Name,
},
Tracing.ExportComponent);
exporter.Start();
var span = tracer
.SpanBuilder("incoming request")
.SetSampler(Samplers.AlwaysSample)
.StartSpan();
Thread.Sleep(TimeSpan.FromSeconds(1));
span.End();
```
### Using Prometheus exporter
Configure Prometheus exporter to have stats collected by Prometheus.
1. Get Prometheus using [getting started guide][prometheus-get-started].
2. Start `PrometheusExporter` as below.
3. See [sample][prometheus-sample] for example use.
``` csharp
var exporter = new PrometheusExporter(
new PrometheusExporterOptions()
{
Url = new Uri("http://localhost:9184/metrics/")
},
Stats.ViewManager);
exporter.Start();
try
{
// record metrics
statsRecorder.NewMeasureMap().Put(VideoSize, values[0] * MiB).Record();
}
finally
{
exporter.Stop();
}
```
### Using Stackdriver Exporter
This sample assumes your code authenticates to Stackdriver APIs using [service account][gcp-auth] with
credentials stored in environment variable GOOGLE_APPLICATION_CREDENTIALS.
When you run on [GAE][GAE], [GKE][GKE] or locally with gcloud sdk installed - this is typically the case.
There is also a constructor for specifying path to the service account credential. See [sample][stackdriver-sample] for details.
1. Add [Stackdriver Exporter package][opencensus-exporter-stackdriver-myget-url] reference.
2. Enable [Stackdriver Trace][stackdriver-trace-setup] API.
3. Enable [Stackdriver Monitoring][stackdriver-monitoring-setup] API.
4. Instantiate a new instance of `StackdriverExporter` with your Google Cloud's ProjectId
5. See [sample][stackdriver-sample] for example use.
``` csharp
var exporter = new StackdriverExporter(
"YOUR-GOOGLE-PROJECT-ID",
Tracing.ExportComponent,
Stats.ViewManager);
exporter.Start();
```
### Using Application Insights exporter
1. Create [Application Insights][ai-get-started] resource.
2. Set instrumentation key via telemetry configuration object
(`new TelemetryConfiguration("iKey")`). This object may be injected via
dependency injection as well.
3. Instantiate a new instance of `ApplicationInsightsExporter`.
4. See [sample][ai-sample] for example use.
``` csharp
var config = new TelemetryConfiguration("iKey")
var exporter = new ApplicationInsightsExporter(
Tracing.ExportComponent,
Stats.ViewManager,
config); // either global or local config can be used
exporter.Start();
```
## Versioning
This library follows [Semantic Versioning][semver].
**GA**: Libraries defined at a GA quality level are stable, and will not
introduce backwards-incompatible changes in any minor or patch releases. We
will address issues and requests with the highest priority. If we were to make
a backwards-incompatible changes on an API, we will first mark the existing API
as deprecated and keep it for 18 months before removing it.
**Beta**: Libraries defined at a Beta quality level are expected to be mostly
stable and we're working towards their release candidate. We will address
issues and requests with a higher priority. There may be backwards incompatible
changes in a minor version release, though not in a patch release. If an
element is part of an API that is only meant to be used by exporters or other
opencensus libraries, then there is no deprecation period. Otherwise, we will
deprecate it for 18 months before removing it, if possible.
[gitter-image]: https://badges.gitter.im/census-instrumentation/lobby.svg
[gitter-url]:https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[opencensus-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.svg
[opencensus-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus
[opencensus-abs-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Abstractions.svg
[opencensus-abs-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Abstractions
[opencensus-exporter-zipkin-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Exporter.Zipkin.svg
[opencensus-exporter-zipkin-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Exporter.Zipkin
[opencensus-exporter-prom-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Exporter.Prometheus.svg
[opencensus-exporter-prom-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Exporter.Prometheus
[opencensus-exporter-ai-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Exporter.ApplicationInsights.svg
[opencensus-exporter-ai-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Exporter.ApplicationInsights
[opencensus-exporter-stackdriver-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Exporter.Stackdriver.svg
[opencensus-exporter-stackdriver-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Exporter.Stackdriver
[opencensus-collect-aspnetcore-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Collector.AspNetCore.svg
[opencensus-collect-aspnetcore-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Collector.AspNetCore
[opencensus-collect-deps-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Collector.Dependencies.svg
[opencensus-collect-deps-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Collector.Dependencies
[opencensus-collect-stackexchange-redis-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Collector.StackExchangeRedis.svg
[opencensus-collect-stackexchange-redis-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Collector.StackExchangeRedis
[opencensus-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.svg
[opencensus-nuget-url]:https://www.nuget.org/packages/OpenCensus
[opencensus-abs-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Abstractions.svg
[opencensus-abs-nuget-url]: https://www.nuget.org/packages/OpenCensus.Abstractions
[opencensus-exporter-zipkin-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Exporter.Zipkin.svg
[opencensus-exporter-zipkin-nuget-url]: https://www.nuget.org/packages/OpenCensus.Exporter.Zipkin
[opencensus-exporter-prom-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Exporter.Prometheus.svg
[opencensus-exporter-prom-nuget-url]: https://www.nuget.org/packages/OpenCensus.Exporter.Prometheus
[opencensus-exporter-ai-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Exporter.ApplicationInsights.svg
[opencensus-exporter-ai-nuget-url]: https://www.nuget.org/packages/OpenCensus.Exporter.ApplicationInsights
[opencensus-exporter-stackdriver-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Exporter.Stackdriver.svg
[opencensus-exporter-stackdriver-nuget-url]: https://www.nuget.org/packages/OpenCensus.Exporter.Stackdriver
[opencensus-collect-aspnetcore-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Collector.AspNetCore.svg
[opencensus-collect-aspnetcore-nuget-url]: https://www.nuget.org/packages/OpenCensus.Collector.AspNetCore
[opencensus-collect-deps-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Collector.Dependencies.svg
[opencensus-collect-deps-nuget-url]: https://www.nuget.org/packages/OpenCensus.Collector.Dependencies
[opencensus-collect-stackexchange-redis-nuget-image]:https://img.shields.io/nuget/vpre/OpenCensus.Collector.StackExchangeRedis.svg
[opencensus-collect-stackexchange-redis-nuget-url]: https://www.nuget.org/packages/OpenCensus.Collector.StackExchangeRedis
[up-for-grabs-issues]: https://github.com/census-instrumentation/opencensus-csharp/issues?q=is%3Aissue+is%3Aopen+label%3Aup-for-grabs
[good-first-issues]: https://github.com/census-instrumentation/opencensus-csharp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22
[zipkin-get-started]: https://zipkin.io/pages/quickstart.html
[ai-get-started]: https://docs.microsoft.com/azure/application-insights
[stackdriver-trace-setup]: https://cloud.google.com/trace/docs/setup/
[stackdriver-monitoring-setup]: https://cloud.google.com/monitoring/api/enable-api
[GAE]: https://cloud.google.com/appengine/docs/flexible/dotnet/quickstart
[GKE]: https://codelabs.developers.google.com/codelabs/cloud-kubernetes-aspnetcore/index.html?index=..%2F..index#0
[gcp-auth]: https://cloud.google.com/docs/authentication/getting-started
[semver]: http://semver.org/
[ai-sample]: https://github.com/census-instrumentation/opencensus-csharp/blob/develop/src/Samples/TestApplicationInsights.cs
[stackdriver-sample]: https://github.com/census-instrumentation/opencensus-csharp/blob/develop/src/Samples/TestStackdriver.cs
[zipkin-sample]: https://github.com/census-instrumentation/opencensus-csharp/blob/develop/src/Samples/TestZipkin.cs
[prometheus-get-started]: https://prometheus.io/docs/introduction/first_steps/
[prometheus-sample]: https://github.com/census-instrumentation/opencensus-csharp/blob/develop/src/Samples/TestPrometheus.cs

62
build/Common.prod.props Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)/OpenCensus.prod.ruleset</CodeAnalysisRuleSet>
<DocumentationFile Condition="$(OS) == 'Windows_NT'">$(OutputPath)/$(TargetFramework)/$(AssemblyName).xml</DocumentationFile>
<PackageOutputPath Condition="$(Build_ArtifactStagingDirectory) != ''">$(Build_ArtifactStagingDirectory)</PackageOutputPath>
</PropertyGroup>
<PropertyGroup Condition="$(OS) == 'Windows_NT'">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)/debug.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<DefineConstants>$(DefineConstants);SIGNED</DefineConstants>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)/stylecop.json" />
</ItemGroup>
<PropertyGroup>
<!--
Semantic Version. See http://semver.org for full details.
Update for every public release.
-->
<SemanticVersionMajor>0</SemanticVersionMajor>
<SemanticVersionMinor>1</SemanticVersionMinor>
<SemanticVersionPatch>0</SemanticVersionPatch>
<!--Valid values: beta1, beta2, EMPTY for stable -->
<PreReleaseMilestone>alpha</PreReleaseMilestone>
<!--
Date when Semantic Version was changed.
Update for every public release.
NOTE!!!!!! Do not update when updating PreReleaseMilestone update
as it will restart file versions so 2.4.0-beta1 may have higher
file version (like 2.4.0.2222) than 2.4.0-beta2 (like 2.4.0.1111)
-->
<SemanticVersionDate>2018-08-25</SemanticVersionDate>
<PreReleaseVersion Condition="'$(PreReleaseVersion)'==''">$([MSBuild]::Divide($([System.DateTime]::Now.Subtract($([System.DateTime]::Parse($(SemanticVersionDate)))).TotalMinutes), 5).ToString('F0'))</PreReleaseVersion>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>$(SemanticVersionMajor).$(SemanticVersionMinor).$(SemanticVersionPatch)</VersionPrefix>
<VersionSuffix>$(PreReleaseMilestone)-$(PreReleaseVersion)</VersionSuffix>
<FileVersion Condition="'$(PreReleaseVersion)' != ''">$(SemanticVersionMajor).$(SemanticVersionMinor).$(SemanticVersionPatch).$(PreReleaseVersion)</FileVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Optional: Declare that the Repository URL can be published to NuSpec -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Optional: Embed source files that are not tracked by the source control manager to the PDB -->
<!-- This is useful if you generate files during the build -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<ItemGroup>
<!-- Required -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-*" PrivateAssets="All"/>
</ItemGroup>
</Project>

18
build/Common.test.props Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="$(OS) == 'Windows_NT'">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)/debug.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<DefineConstants>$(DefineConstants);SIGNED</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))\build\OpenCensus.test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)/stylecop.json" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="OpenCensus SDK Rules" Description="Open Census SDK ruleset for product code." ToolsVersion="15.0">
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
<Name Resource="OpenCensusSDKRules_Name" />
<Description Resource="OpenCensusSDKRules_Description" />
</Localization>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1000" Action="Warning" />
<Rule Id="SA1001" Action="Warning" />
<Rule Id="SA1002" Action="Warning" />
<Rule Id="SA1003" Action="Warning" />
<Rule Id="SA1004" Action="Warning" />
<Rule Id="SA1005" Action="Warning" />
<Rule Id="SA1006" Action="Warning" />
<Rule Id="SA1007" Action="Warning" />
<Rule Id="SA1008" Action="Warning" />
<Rule Id="SA1009" Action="Warning" />
<Rule Id="SA1010" Action="Warning" />
<Rule Id="SA1011" Action="Warning" />
<Rule Id="SA1012" Action="Warning" />
<Rule Id="SA1013" Action="Warning" />
<Rule Id="SA1014" Action="Warning" />
<Rule Id="SA1015" Action="Warning" />
<Rule Id="SA1016" Action="Warning" />
<Rule Id="SA1017" Action="Warning" />
<Rule Id="SA1018" Action="Warning" />
<Rule Id="SA1019" Action="Warning" />
<Rule Id="SA1020" Action="Warning" />
<Rule Id="SA1021" Action="Warning" />
<Rule Id="SA1022" Action="Warning" />
<Rule Id="SA1023" Action="Warning" />
<Rule Id="SA1024" Action="Warning" />
<Rule Id="SA1025" Action="Warning" />
<Rule Id="SA1026" Action="Warning" />
<Rule Id="SA1027" Action="Warning" />
<Rule Id="SA1028" Action="None" />
<Rule Id="SA1100" Action="Warning" />
<Rule Id="SA1101" Action="Warning" />
<Rule Id="SA1102" Action="Warning" />
<Rule Id="SA1103" Action="Warning" />
<Rule Id="SA1104" Action="Warning" />
<Rule Id="SA1105" Action="Warning" />
<Rule Id="SA1106" Action="Warning" />
<Rule Id="SA1107" Action="Warning" />
<Rule Id="SA1108" Action="Warning" />
<Rule Id="SA1110" Action="Warning" />
<Rule Id="SA1111" Action="Warning" />
<Rule Id="SA1112" Action="Warning" />
<Rule Id="SA1113" Action="None" />
<Rule Id="SA1114" Action="None" />
<Rule Id="SA1115" Action="Warning" />
<Rule Id="SA1116" Action="None" />
<Rule Id="SA1117" Action="None" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1119" Action="Warning" />
<Rule Id="SA1120" Action="Warning" />
<Rule Id="SA1121" Action="None" />
<Rule Id="SA1122" Action="Warning" />
<Rule Id="SA1123" Action="Warning" />
<Rule Id="SA1124" Action="None" />
<Rule Id="SA1125" Action="Warning" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1128" Action="None" />
<Rule Id="SA1129" Action="None" />
<Rule Id="SA1130" Action="Warning" />
<Rule Id="SA1131" Action="None" />
<Rule Id="SA1132" Action="None" />
<Rule Id="SA1133" Action="Warning" />
<Rule Id="SA1134" Action="None" />
<Rule Id="SA1200" Action="Warning" />
<Rule Id="SA1201" Action="Warning" />
<Rule Id="SA1202" Action="Warning" />
<Rule Id="SA1203" Action="Warning" />
<Rule Id="SA1204" Action="Warning" />
<Rule Id="SA1205" Action="Warning" />
<Rule Id="SA1206" Action="Warning" />
<Rule Id="SA1207" Action="Warning" />
<Rule Id="SA1208" Action="Warning" />
<Rule Id="SA1209" Action="Warning" />
<Rule Id="SA1210" Action="Warning" />
<Rule Id="SA1211" Action="Warning" />
<Rule Id="SA1212" Action="Warning" />
<Rule Id="SA1213" Action="Warning" />
<Rule Id="SA1214" Action="Warning" />
<Rule Id="SA1216" Action="Warning" />
<Rule Id="SA1217" Action="Warning" />
<Rule Id="SA1300" Action="Warning" />
<Rule Id="SA1302" Action="Warning" />
<Rule Id="SA1303" Action="Warning" />
<Rule Id="SA1304" Action="Warning" />
<Rule Id="SA1306" Action="Warning" />
<Rule Id="SA1307" Action="Warning" />
<Rule Id="SA1308" Action="Warning" />
<Rule Id="SA1309" Action="Warning" />
<Rule Id="SA1310" Action="Warning" />
<Rule Id="SA1311" Action="Warning" />
<Rule Id="SA1312" Action="Warning" />
<Rule Id="SA1313" Action="Warning" />
<Rule Id="SA1400" Action="Warning" />
<Rule Id="SA1401" Action="None" />
<Rule Id="SA1402" Action="Warning" />
<Rule Id="SA1403" Action="Warning" />
<Rule Id="SA1404" Action="Warning" />
<Rule Id="SA1405" Action="Warning" />
<Rule Id="SA1406" Action="Warning" />
<Rule Id="SA1407" Action="Warning" />
<Rule Id="SA1408" Action="Warning" />
<Rule Id="SA1410" Action="Warning" />
<Rule Id="SA1411" Action="Warning" />
<Rule Id="SA1500" Action="Warning" />
<Rule Id="SA1501" Action="Warning" />
<Rule Id="SA1502" Action="Warning" />
<Rule Id="SA1503" Action="Warning" />
<Rule Id="SA1504" Action="Warning" />
<Rule Id="SA1505" Action="Warning" />
<Rule Id="SA1506" Action="Warning" />
<Rule Id="SA1507" Action="Warning" />
<Rule Id="SA1508" Action="Warning" />
<Rule Id="SA1509" Action="Warning" />
<Rule Id="SA1510" Action="Warning" />
<Rule Id="SA1511" Action="Warning" />
<Rule Id="SA1512" Action="None" />
<Rule Id="SA1513" Action="Warning" />
<Rule Id="SA1514" Action="Warning" />
<Rule Id="SA1515" Action="None" />
<Rule Id="SA1516" Action="Warning" />
<Rule Id="SA1517" Action="Warning" />
<Rule Id="SA1518" Action="Warning" />
<Rule Id="SA1519" Action="Warning" />
<Rule Id="SA1520" Action="Warning" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1601" Action="Warning" />
<Rule Id="SA1602" Action="Warning" />
<Rule Id="SA1604" Action="Warning" />
<Rule Id="SA1605" Action="Warning" />
<Rule Id="SA1606" Action="Warning" />
<Rule Id="SA1607" Action="Warning" />
<Rule Id="SA1608" Action="Warning" />
<Rule Id="SA1610" Action="Warning" />
<Rule Id="SA1611" Action="Warning" />
<Rule Id="SA1612" Action="Warning" />
<Rule Id="SA1613" Action="Warning" />
<Rule Id="SA1614" Action="Warning" />
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1616" Action="Warning" />
<Rule Id="SA1617" Action="Warning" />
<Rule Id="SA1618" Action="None" />
<Rule Id="SA1619" Action="Warning" />
<Rule Id="SA1620" Action="Warning" />
<Rule Id="SA1621" Action="Warning" />
<Rule Id="SA1622" Action="Warning" />
<Rule Id="SA1623" Action="Warning" />
<Rule Id="SA1624" Action="Warning" />
<Rule Id="SA1625" Action="Warning" />
<Rule Id="SA1626" Action="Warning" />
<Rule Id="SA1627" Action="Warning" />
<Rule Id="SA1633" Action="Error" />
<Rule Id="SA1634" Action="Warning" />
<Rule Id="SA1635" Action="Warning" />
<Rule Id="SA1636" Action="None" />
<Rule Id="SA1637" Action="Warning" />
<Rule Id="SA1638" Action="Warning" />
<Rule Id="SA1640" Action="Warning" />
<Rule Id="SA1641" Action="Warning" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1643" Action="Warning" />
<Rule Id="SA1648" Action="Warning" />
<Rule Id="SA1649" Action="Warning" />
<Rule Id="SA1651" Action="Warning" />
<Rule Id="SA1652" Action="Warning" />
</Rules>
</RuleSet>

View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="OpenCensus SDK Rules" Description="Open Census SDK ruleset for product code." ToolsVersion="15.0">
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
<Name Resource="OpenCensusSDKRules_Name" />
<Description Resource="OpenCensusSDKRules_Description" />
</Localization>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1000" Action="Error" />
<Rule Id="SA1001" Action="Error" />
<Rule Id="SA1002" Action="Error" />
<Rule Id="SA1003" Action="Error" />
<Rule Id="SA1004" Action="Error" />
<Rule Id="SA1005" Action="Error" />
<Rule Id="SA1006" Action="Error" />
<Rule Id="SA1007" Action="Error" />
<Rule Id="SA1008" Action="Error" />
<Rule Id="SA1009" Action="Error" />
<Rule Id="SA1010" Action="Error" />
<Rule Id="SA1011" Action="Error" />
<Rule Id="SA1012" Action="Error" />
<Rule Id="SA1013" Action="Error" />
<Rule Id="SA1014" Action="Error" />
<Rule Id="SA1015" Action="Error" />
<Rule Id="SA1016" Action="Error" />
<Rule Id="SA1017" Action="Error" />
<Rule Id="SA1018" Action="Error" />
<Rule Id="SA1019" Action="Error" />
<Rule Id="SA1020" Action="Error" />
<Rule Id="SA1021" Action="Error" />
<Rule Id="SA1022" Action="Error" />
<Rule Id="SA1023" Action="Error" />
<Rule Id="SA1024" Action="Error" />
<Rule Id="SA1025" Action="Error" />
<Rule Id="SA1026" Action="Error" />
<Rule Id="SA1027" Action="Error" />
<Rule Id="SA1028" Action="Error" />
<Rule Id="SA1100" Action="Error" />
<Rule Id="SA1101" Action="Error" />
<Rule Id="SA1102" Action="Error" />
<Rule Id="SA1103" Action="Error" />
<Rule Id="SA1104" Action="Error" />
<Rule Id="SA1105" Action="Error" />
<Rule Id="SA1106" Action="Error" />
<Rule Id="SA1107" Action="Error" />
<Rule Id="SA1108" Action="Error" />
<Rule Id="SA1110" Action="Error" />
<Rule Id="SA1111" Action="Error" />
<Rule Id="SA1112" Action="Error" />
<Rule Id="SA1113" Action="Error" />
<Rule Id="SA1114" Action="Error" />
<Rule Id="SA1115" Action="Error" />
<Rule Id="SA1116" Action="Error" />
<Rule Id="SA1117" Action="Error" />
<Rule Id="SA1118" Action="Error" />
<Rule Id="SA1119" Action="Error" />
<Rule Id="SA1120" Action="Error" />
<Rule Id="SA1121" Action="Error" />
<Rule Id="SA1122" Action="Error" />
<Rule Id="SA1123" Action="Error" />
<Rule Id="SA1124" Action="Error" />
<Rule Id="SA1125" Action="Error" />
<Rule Id="SA1127" Action="Error" />
<Rule Id="SA1128" Action="Error" />
<Rule Id="SA1129" Action="Error" />
<Rule Id="SA1130" Action="Error" />
<Rule Id="SA1131" Action="Error" />
<Rule Id="SA1132" Action="Error" />
<Rule Id="SA1133" Action="Error" />
<Rule Id="SA1134" Action="Error" />
<Rule Id="SA1200" Action="Error" />
<Rule Id="SA1201" Action="Error" />
<Rule Id="SA1202" Action="Error" />
<Rule Id="SA1203" Action="Error" />
<Rule Id="SA1204" Action="Error" />
<Rule Id="SA1205" Action="Error" />
<Rule Id="SA1206" Action="Error" />
<Rule Id="SA1207" Action="Error" />
<Rule Id="SA1208" Action="Error" />
<Rule Id="SA1209" Action="Error" />
<Rule Id="SA1210" Action="Error" />
<Rule Id="SA1211" Action="Error" />
<Rule Id="SA1212" Action="Error" />
<Rule Id="SA1213" Action="Error" />
<Rule Id="SA1214" Action="Error" />
<Rule Id="SA1216" Action="Error" />
<Rule Id="SA1217" Action="Error" />
<Rule Id="SA1300" Action="Error" />
<Rule Id="SA1302" Action="Error" />
<Rule Id="SA1303" Action="Error" />
<Rule Id="SA1304" Action="Error" />
<Rule Id="SA1306" Action="Error" />
<Rule Id="SA1307" Action="Error" />
<Rule Id="SA1308" Action="Error" />
<Rule Id="SA1309" Action="Error" />
<Rule Id="SA1310" Action="Error" />
<Rule Id="SA1311" Action="Error" />
<Rule Id="SA1312" Action="Error" />
<Rule Id="SA1313" Action="Error" />
<Rule Id="SA1400" Action="Error" />
<Rule Id="SA1401" Action="None" />
<Rule Id="SA1402" Action="Error" />
<Rule Id="SA1403" Action="Error" />
<Rule Id="SA1404" Action="Error" />
<Rule Id="SA1405" Action="Error" />
<Rule Id="SA1406" Action="Error" />
<Rule Id="SA1407" Action="Error" />
<Rule Id="SA1408" Action="Error" />
<Rule Id="SA1410" Action="Error" />
<Rule Id="SA1411" Action="Error" />
<Rule Id="SA1500" Action="Error" />
<Rule Id="SA1501" Action="Error" />
<Rule Id="SA1502" Action="Error" />
<Rule Id="SA1503" Action="Error" />
<Rule Id="SA1504" Action="Error" />
<Rule Id="SA1505" Action="Error" />
<Rule Id="SA1506" Action="Error" />
<Rule Id="SA1507" Action="Error" />
<Rule Id="SA1508" Action="Error" />
<Rule Id="SA1509" Action="Error" />
<Rule Id="SA1510" Action="Error" />
<Rule Id="SA1511" Action="Error" />
<Rule Id="SA1512" Action="None" />
<Rule Id="SA1513" Action="Error" />
<Rule Id="SA1514" Action="Error" />
<Rule Id="SA1515" Action="Error" />
<Rule Id="SA1516" Action="Error" />
<Rule Id="SA1517" Action="Error" />
<Rule Id="SA1518" Action="Error" />
<Rule Id="SA1519" Action="Error" />
<Rule Id="SA1520" Action="Error" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1601" Action="Error" />
<Rule Id="SA1602" Action="Error" />
<Rule Id="SA1604" Action="Error" />
<Rule Id="SA1605" Action="Error" />
<Rule Id="SA1606" Action="Error" />
<Rule Id="SA1607" Action="Error" />
<Rule Id="SA1608" Action="Error" />
<Rule Id="SA1610" Action="Error" />
<Rule Id="SA1611" Action="Error" />
<Rule Id="SA1612" Action="Error" />
<Rule Id="SA1613" Action="Error" />
<Rule Id="SA1614" Action="Error" />
<Rule Id="SA1615" Action="Error" />
<Rule Id="SA1616" Action="Error" />
<Rule Id="SA1617" Action="Error" />
<Rule Id="SA1618" Action="Error" />
<Rule Id="SA1619" Action="Error" />
<Rule Id="SA1620" Action="Error" />
<Rule Id="SA1621" Action="Error" />
<Rule Id="SA1622" Action="Error" />
<Rule Id="SA1623" Action="Error" />
<Rule Id="SA1624" Action="Error" />
<Rule Id="SA1625" Action="Error" />
<Rule Id="SA1626" Action="Error" />
<Rule Id="SA1627" Action="Error" />
<Rule Id="SA1633" Action="Error" />
<Rule Id="SA1634" Action="Error" />
<Rule Id="SA1635" Action="Error" />
<Rule Id="SA1636" Action="Error" />
<Rule Id="SA1637" Action="Error" />
<Rule Id="SA1638" Action="Error" />
<Rule Id="SA1640" Action="Error" />
<Rule Id="SA1641" Action="Error" />
<Rule Id="SA1642" Action="Error" />
<Rule Id="SA1643" Action="Error" />
<Rule Id="SA1648" Action="Error" />
<Rule Id="SA1649" Action="Error" />
<Rule Id="SA1651" Action="Error" />
<Rule Id="SA1652" Action="Warning" />
</Rules>
</RuleSet>

View File

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="OpenCensus SDK Test code Rules" Description="Open Census SDK ruleset for test code." ToolsVersion="15.0">
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
<Name Resource="OpenCensusSDKRules_Name" />
<Description Resource="OpenCensusSDKRules_Description" />
</Localization>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1000" Action="None" />
<Rule Id="SA1001" Action="None" />
<Rule Id="SA1002" Action="None" />
<Rule Id="SA1003" Action="None" />
<Rule Id="SA1004" Action="None" />
<Rule Id="SA1005" Action="None" />
<Rule Id="SA1006" Action="None" />
<Rule Id="SA1007" Action="None" />
<Rule Id="SA1008" Action="None" />
<Rule Id="SA1009" Action="None" />
<Rule Id="SA1010" Action="None" />
<Rule Id="SA1011" Action="None" />
<Rule Id="SA1012" Action="None" />
<Rule Id="SA1013" Action="None" />
<Rule Id="SA1014" Action="None" />
<Rule Id="SA1015" Action="None" />
<Rule Id="SA1016" Action="None" />
<Rule Id="SA1017" Action="None" />
<Rule Id="SA1018" Action="None" />
<Rule Id="SA1019" Action="None" />
<Rule Id="SA1020" Action="None" />
<Rule Id="SA1021" Action="None" />
<Rule Id="SA1022" Action="None" />
<Rule Id="SA1023" Action="None" />
<Rule Id="SA1024" Action="None" />
<Rule Id="SA1025" Action="None" />
<Rule Id="SA1026" Action="None" />
<Rule Id="SA1027" Action="None" />
<Rule Id="SA1028" Action="None" />
<Rule Id="SA1100" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1102" Action="None" />
<Rule Id="SA1103" Action="None" />
<Rule Id="SA1104" Action="None" />
<Rule Id="SA1105" Action="None" />
<Rule Id="SA1106" Action="None" />
<Rule Id="SA1107" Action="None" />
<Rule Id="SA1108" Action="None" />
<Rule Id="SA1110" Action="None" />
<Rule Id="SA1111" Action="None" />
<Rule Id="SA1112" Action="None" />
<Rule Id="SA1113" Action="None" />
<Rule Id="SA1114" Action="None" />
<Rule Id="SA1115" Action="None" />
<Rule Id="SA1116" Action="None" />
<Rule Id="SA1117" Action="None" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1119" Action="None" />
<Rule Id="SA1120" Action="None" />
<Rule Id="SA1121" Action="None" />
<Rule Id="SA1122" Action="None" />
<Rule Id="SA1123" Action="None" />
<Rule Id="SA1124" Action="None" />
<Rule Id="SA1125" Action="None" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1128" Action="None" />
<Rule Id="SA1129" Action="None" />
<Rule Id="SA1130" Action="None" />
<Rule Id="SA1131" Action="None" />
<Rule Id="SA1132" Action="None" />
<Rule Id="SA1133" Action="None" />
<Rule Id="SA1134" Action="None" />
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1203" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1205" Action="None" />
<Rule Id="SA1206" Action="None" />
<Rule Id="SA1207" Action="None" />
<Rule Id="SA1208" Action="None" />
<Rule Id="SA1209" Action="None" />
<Rule Id="SA1210" Action="None" />
<Rule Id="SA1211" Action="None" />
<Rule Id="SA1212" Action="None" />
<Rule Id="SA1213" Action="None" />
<Rule Id="SA1214" Action="None" />
<Rule Id="SA1216" Action="None" />
<Rule Id="SA1217" Action="None" />
<Rule Id="SA1300" Action="None" />
<Rule Id="SA1302" Action="None" />
<Rule Id="SA1303" Action="None" />
<Rule Id="SA1304" Action="None" />
<Rule Id="SA1306" Action="None" />
<Rule Id="SA1307" Action="None" />
<Rule Id="SA1308" Action="None" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1310" Action="None" />
<Rule Id="SA1311" Action="None" />
<Rule Id="SA1312" Action="None" />
<Rule Id="SA1313" Action="None" />
<Rule Id="SA1400" Action="None" />
<Rule Id="SA1401" Action="None" />
<Rule Id="SA1402" Action="None" />
<Rule Id="SA1403" Action="None" />
<Rule Id="SA1404" Action="None" />
<Rule Id="SA1405" Action="None" />
<Rule Id="SA1406" Action="None" />
<Rule Id="SA1407" Action="None" />
<Rule Id="SA1408" Action="None" />
<Rule Id="SA1410" Action="None" />
<Rule Id="SA1411" Action="None" />
<Rule Id="SA1500" Action="None" />
<Rule Id="SA1501" Action="None" />
<Rule Id="SA1502" Action="None" />
<Rule Id="SA1503" Action="None" />
<Rule Id="SA1504" Action="None" />
<Rule Id="SA1505" Action="None" />
<Rule Id="SA1506" Action="None" />
<Rule Id="SA1507" Action="None" />
<Rule Id="SA1508" Action="None" />
<Rule Id="SA1509" Action="None" />
<Rule Id="SA1510" Action="None" />
<Rule Id="SA1511" Action="None" />
<Rule Id="SA1512" Action="None" />
<Rule Id="SA1513" Action="None" />
<Rule Id="SA1514" Action="None" />
<Rule Id="SA1515" Action="None" />
<Rule Id="SA1516" Action="None" />
<Rule Id="SA1517" Action="None" />
<Rule Id="SA1518" Action="None" />
<Rule Id="SA1519" Action="None" />
<Rule Id="SA1520" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1601" Action="None" />
<Rule Id="SA1602" Action="None" />
<Rule Id="SA1604" Action="None" />
<Rule Id="SA1605" Action="None" />
<Rule Id="SA1606" Action="None" />
<Rule Id="SA1607" Action="None" />
<Rule Id="SA1608" Action="None" />
<Rule Id="SA1610" Action="None" />
<Rule Id="SA1611" Action="None" />
<Rule Id="SA1612" Action="None" />
<Rule Id="SA1613" Action="None" />
<Rule Id="SA1614" Action="None" />
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1616" Action="None" />
<Rule Id="SA1617" Action="None" />
<Rule Id="SA1618" Action="None" />
<Rule Id="SA1619" Action="None" />
<Rule Id="SA1620" Action="None" />
<Rule Id="SA1621" Action="None" />
<Rule Id="SA1622" Action="None" />
<Rule Id="SA1623" Action="None" />
<Rule Id="SA1624" Action="None" />
<Rule Id="SA1625" Action="None" />
<Rule Id="SA1626" Action="None" />
<Rule Id="SA1627" Action="None" />
<Rule Id="SA1633" Action="Error" />
<Rule Id="SA1634" Action="None" />
<Rule Id="SA1635" Action="None" />
<Rule Id="SA1636" Action="None" />
<Rule Id="SA1637" Action="None" />
<Rule Id="SA1638" Action="None" />
<Rule Id="SA1640" Action="None" />
<Rule Id="SA1641" Action="None" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1643" Action="None" />
<Rule Id="SA1648" Action="None" />
<Rule Id="SA1649" Action="None" />
<Rule Id="SA1651" Action="None" />
<Rule Id="SA1652" Action="None" />
</Rules>
</RuleSet>

BIN
build/debug.snk Normal file

Binary file not shown.

15
build/stylecop.json Normal file
View File

@ -0,0 +1,15 @@
{
// ACTION REQUIRED: This file was automatically added to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "OpenCensus Authors",
"copyrightText": "Copyright 2018, OpenCensus Authors\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
}
}
}

41
docs/error-handling.md Normal file
View File

@ -0,0 +1,41 @@
# Error handling in Open Census C# SDK
Open Census is a library that will in many cases run in a context of customer
app performing non-essential from app business logic perspective operations.
Open Census SDK also can and will often be enabled via platform extensibility
mechanisms and potentially only enabled in runtime. Which makes the use of SDK
non-obvious for the end user and sometimes outside of the end user control.
This makes some unique requirements for Open Census error handling practices.
## Basic error handling principles
Open Census SDK must not throw or leak unhandled or user unhandled exceptions.
1. APIs must not throw or leak unhandled or user unhandled exceptions when the
API is used incorrectly by the developer. Smart defaults should be used so
that the SDK generally works.
2. SDK must not throw or leak unhandled or user unhandled exceptions for
configuration errors.
3. SDK must not throw or leak unhandled or user unhandled exceptions for errors
in their own operations. Examples: telemetry cannot be sent because the
endpoint is down or location information is not available because device
owner has disabled it.
## Guidance
1. In .NET 4.0 and above, catching all exceptions will not catch corrupted
state exceptions (CSEs).
- We want this behavior—dont catch CSEs
- This allows exceptions like stack overflow, access violation to flow through
- More information: http://msdn.microsoft.com/en-us/magazine/dd419661.aspx
2. Every background operation callback, Task or Thread method should have a
global `try{}catch` statement to ensure reliability of an app.
3. When catching all exceptions in other cases, reduce the scope of the `try` as
much as possible.
4. In general, don't catch, filter, and rethrow
- Catch all exceptions and log error
- If you must rethrow use `throw;` not `throw ex;`. It will ensure
original call stack is preserved.
5. Beware of any call to external callbacks or override-able interface. Expect
them to throw.

103
docs/error-logging.md Normal file
View File

@ -0,0 +1,103 @@
# Error logging
This document explains how Open Census SDK logs information about it's own
execution.
There are the following scenarios for SDK manageability:
1. Send error & warning logs to the back-end for customer self-troubleshooting.
2. Visualize OC SDK health in external tools.
3. Visualize OC SDK health in Z-Pages.
4. Show errors/warnings/information in Visual Studio F5 debug window.
5. Testing no debugger troubleshooting.
6. Customer support collect verbose logs.
## Definition of verbosity levels
The following severity levels are defined for SDK logs.
### Severity `Error`
Problem in SDK operation resulted in data loss or inability to collect data.
### Severity `Warning`
Problem in SDK operation that MAY result in data loss if not attended to.
`Warning` level may also identify data quality problem.
### Severity `Informational`
Major, most often rarely happening operation completion.
### Severity `Verbose`
All other logs. Typically used for troubleshooting of a hard to reproduce
issues or issues happening in specific production environments.
## Logging with EventSource
1. Find or create an assembly-specific `internal` class inherited from
`EventSource`.
2. Prefix the name of EventSource with `OpenCensus-` using class attribute like
this: `[EventSource(Name = "OpenCensus-Base")]`.
3. Create a new `Event` method with the arguments that needs to be logged. Each
event should have index, message and event severity (level). It is a good
practice to include event severity (level) into the method name.
4. Use the following rules to pick event index:
1. Do not reorder existing event method indexes. Otherwise versioning of
logs metadata will not work well.
2. Do not put large gaps between indices. E.g. use sequential indices
instead of events categorization based on index (`1X` for one category,
`2X` for another). Unassigned indices in `1X` category will affect
logging performance.
5. Use the following rules to author the event message:
1. Make event description actionable and explain the effect of the problem.
For instance, instead of *"No span in current context"* use something
like *"No span in current context. Span name will not be updated. It may
indicate incorrect usage of Open Census API - please ensure span wasn't
overridden explicitly in your code or by other module."*
6. Use the following definition of the severity from the next section.
7. Follow the performance optimization techniques.
## Minimizing logging performance impact
### Pass object references
EventSource requires to use primitive types like `int` or `string` in `Write`
method. This limitation requires to format complex types like `Exception` before
calling trace statement.
Since formatting happens before calling `Write` method it will be called
unconditionally whether listener enabled or not. To minimize performance hit
create `NonEvent` methods in EventSource that accept complex types and check
`Log.IsEnabled` before serializing those and passing to `Event` methods.
### Diagnostics events throttling
Throttling is required for the following scenarios:
- Minimize traffic we use to report problems to portal
- Make sure *.etl are not overloaded with similar errors
Logs subscribers will implement throttling logic. However log producer may have
an additional logic to prevent excessive logging. For instance, if problem
cannot be resolved in runtime - producer of the `Error` log may decide to only
log it once or once in a while. Note, this technique should be used carefully
as not every log subscriber can be enabled from the process start and may miss
this important error message.
## Subscribing to EventSource
EventSource allows us to separate logic of tracing and delivering those traces
to different channels. Default ETW subscriber works out of the box. For all
other channels in-process subscribers can be used for data delivery.
![event-source-listeners](event-source-listeners.png)
## EventSource vs. using SDK itself
1. No support for `IsEnabled` when exporter/listener exists. It's important for
verbose logging.
2. ETW channel is not supported.
3. In-process subscription/extensibility is not supported.
4. Logging should be more reliable then SDK itself.

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
packages-microsoft-prod.deb Normal file

Binary file not shown.

View File

@ -0,0 +1,137 @@
// <copyright file="Duration.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Common
{
using System;
/// <summary>
/// Represents duration with the nanoseconds precition.
/// </summary>
public sealed class Duration : IComparable<Duration>
{
private const long MaxSeconds = 315576000000L;
private const int MaxNanos = 999999999;
private static readonly Duration Zero = new Duration(0, 0);
private Duration(long seconds, int nanos)
{
this.Seconds = seconds;
this.Nanos = nanos;
}
/// <summary>
/// Gets the number of second in duration.
/// </summary>
public long Seconds { get; }
/// <summary>
/// Gets the number of nanoseconds in duration.
/// </summary>
public int Nanos { get; }
/// <summary>
/// Creates a new instance of <see cref="Duration" /> class.
/// </summary>
/// <param name="seconds">Total seconds.</param>
/// <param name="nanos">Nanoseconds part of a duration up to 999999999.</param>
/// <returns>New instance of <see cref="Duration" /> class.</returns>
public static Duration Create(long seconds, int nanos)
{
if (seconds < -MaxSeconds || seconds > MaxSeconds)
{
return Zero;
}
if (nanos < -MaxNanos || nanos > MaxNanos)
{
return Zero;
}
if ((seconds < 0 && nanos > 0) || (seconds > 0 && nanos < 0))
{
return Zero;
}
return new Duration(seconds, nanos);
}
/// <summary>
/// Creates a new instance of <see cref="Duration" /> class.
/// </summary>
/// <param name="duration">Duration as TimeStamp.</param>
/// <returns>New instance of <see cref="Duration" /> class.</returns>
public static Duration Create(TimeSpan duration)
{
var seconds = duration.Ticks / TimeSpan.TicksPerSecond;
int nanoseconds = (int)(duration.Ticks % TimeSpan.TicksPerSecond) * 100;
return Create(seconds, nanoseconds);
}
/// <summary>
/// Compares durations.
/// </summary>
/// <param name="other"><see cref="Duration" /> instasnce to compare to.</param>
/// <returns>Zero if equal, -1 when lesser and +1 when greater than given value.</returns>
public int CompareTo(Duration other)
{
int cmp = (this.Seconds < other.Seconds) ? -1 : ((this.Seconds > other.Seconds) ? 1 : 0);
if (cmp != 0)
{
return cmp;
}
return (this.Nanos < other.Nanos) ? -1 : ((this.Nanos > other.Nanos) ? 1 : 0);
}
/// <inheritdoc/>
public override string ToString()
{
return "Duration{"
+ "seconds=" + this.Seconds + ", "
+ "nanos=" + this.Nanos
+ "}";
}
/// <inheritdoc/>
public override bool Equals(object o)
{
if (o == this)
{
return true;
}
if (o is Duration that)
{
return (this.Seconds == that.Seconds)
&& (this.Nanos == that.Nanos);
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
long h = 1;
h *= 1000003;
h ^= (this.Seconds >> 32) ^ this.Seconds;
h *= 1000003;
h ^= this.Nanos;
return (int)h;
}
}
}

View File

@ -0,0 +1,28 @@
// <copyright file="IScope.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Common
{
using System;
/// <summary>
/// Scope marker. Used as a syntactic sugar in methods like StartScopedSpan so it can be
/// wrapped in "using" block with automatic scope completion.
/// </summary>
public interface IScope : IDisposable
{
}
}

View File

@ -0,0 +1,81 @@
// <copyright file="Timer.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Internal
{
using System;
using System.Diagnostics;
/// <summary>
/// Gets the current time based on start time and precise duration.
/// </summary>
public sealed class Timer
{
private readonly DateTimeOffset timestamp;
private readonly Func<TimeSpan> stopwatch;
private Timer(DateTimeOffset timestamp, Func<TimeSpan> watch)
{
this.timestamp = timestamp;
this.stopwatch = watch;
}
/// <summary>
/// Gets the time of creation of this timer.
/// </summary>
/// <returns>Time of this timer creation.</returns>
public DateTimeOffset StartTime
{
get
{
return this.timestamp;
}
}
/// <summary>
/// Gets the current timestamp based on start time and high precision elapsed time.
/// </summary>
/// <returns>Current timestamp based on start time and high precision elapsed time.</returns>
public DateTimeOffset Now
{
get
{
return this.timestamp.Add(this.stopwatch());
}
}
/// <summary>
/// Creates a new instance of a timer.
/// </summary>
/// <returns>New insance of a timer.</returns>
public static Timer StartNew()
{
var stopwatch = Stopwatch.StartNew();
return new Timer(DateTimeOffset.Now, () => stopwatch.Elapsed);
}
/// <summary>
/// Creates a new instance of a timer with the given start time. Used for test purposes.
/// </summary>
/// <param name="time">Start time to use in this timer.</param>
/// <param name="watch">Stopwatch to use. Should be started.</param>
/// <returns>New instance of a timer.</returns>
public static Timer StartNew(DateTimeOffset time, Func<TimeSpan> watch)
{
return new Timer(time, watch);
}
}
}

View File

@ -0,0 +1,229 @@
// <copyright file="Timestamp.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Common
{
using System;
/// <summary>
/// Timestamp with the nanoseconds precision.
/// </summary>
public sealed class Timestamp : IComparable<Timestamp>, IComparable
{
/// <summary>
/// Represents zero timestamp.
/// </summary>
public static readonly Timestamp Zero = new Timestamp(0, 0);
private const long MaxSeconds = 315576000000L;
private const int MaxNanos = 999999999;
private const long MillisPerSecond = 1000L;
private const long NanosPerMilli = 1000 * 1000;
private const long NanosPerSecond = NanosPerMilli * MillisPerSecond;
internal Timestamp(long seconds, int nanos)
{
this.Seconds = seconds;
this.Nanos = nanos;
}
/// <summary>
/// Gets the number of seconds since the Unix Epoch represented by this timestamp.
/// </summary>
public long Seconds { get; }
/// <summary>
/// Gets the the number of nanoseconds after the number of seconds since the Unix Epoch represented
/// by this timestamp.
/// </summary>
public int Nanos { get; }
/// <summary>
/// Creates an instance of <see cref="Timestamp" /> class with the given seconds and nanoseconds values.
/// </summary>
/// <param name="seconds">Total number of seconds since the Unix Epoch represented by this <see cref="Timestamp"/>.</param>
/// <param name="nanos">The number of nanoseconds after the number of seconds since the Unix Epoch represented by this <see cref="Timestamp"/>.</param>
/// <returns>New instance of <see cref="Timestamp"/>.</returns>
public static Timestamp Create(long seconds, int nanos)
{
// TODO:
if (seconds < -MaxSeconds || seconds > MaxSeconds)
{
return new Timestamp(0, 0);
}
if (nanos < 0 || nanos > MaxNanos)
{
return new Timestamp(0, 0);
}
return new Timestamp(seconds, nanos);
}
/// <summary>
/// Creates an instance of <see cref="Timestamp" /> class with the given total milliseconds since Unix Epoch.
/// </summary>
/// <param name="millis">Total number of milliseconds since the Unix Epoch represented by this <see cref="Timestamp"/>.</param>
/// <returns>New instance of <see cref="Timestamp"/>.</returns>
public static Timestamp FromMillis(long millis)
{
Timestamp zero = new Timestamp(0, 0);
long nanos = millis * NanosPerMilli;
return zero.Plus(0, nanos);
}
/// <summary>
/// Creates an instance of <see cref="Timestamp" /> class with the given time as <see cref="DateTimeOffset"/>.
/// </summary>
/// <param name="time">Time to convert to <see cref="Timestamp"/>.</param>
/// <returns>New instance of <see cref="Timestamp"/>.</returns>
public static Timestamp FromDateTimeOffset(DateTimeOffset time)
{
long seconds = 0;
#if NET45
var unixZero = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
seconds = (int)Math.Floor(time.Subtract(unixZero).TotalSeconds);
#else
seconds = time.ToUnixTimeSeconds();
#endif
int nanos = (int)time.Subtract(new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero)).Subtract(TimeSpan.FromSeconds(seconds)).Ticks * 100;
return Timestamp.Create(seconds, nanos);
}
/// <summary>
/// Adds duration to the timestamp.
/// </summary>
/// <param name="duration">Duration to add to the timestamp.</param>
/// <returns>Returns the timestamp with added duration.</returns>
public Timestamp AddDuration(Duration duration)
{
return this.Plus(duration.Seconds, duration.Nanos);
}
/// <summary>
/// Adds nanosToAdd nanosecond to the current timestamp.
/// </summary>
/// <param name="nanosToAdd">Number of nanoseconds to add.</param>
/// <returns>Returns the timstemp with added nanoseconds.</returns>
public Timestamp AddNanos(long nanosToAdd)
{
return this.Plus(0, nanosToAdd);
}
/// <summary>
/// Substructs timestamp from the current timestamp. Typically to calculate duration.
/// </summary>
/// <param name="timestamp">Timestamp to substruct.</param>
/// <returns>Returns the timestamp with the substructed duration.</returns>
public Duration SubtractTimestamp(Timestamp timestamp)
{
long durationSeconds = this.Seconds - timestamp.Seconds;
int durationNanos = this.Nanos - timestamp.Nanos;
if (durationSeconds < 0 && durationNanos > 0)
{
durationSeconds += 1;
durationNanos = (int)(durationNanos - NanosPerSecond);
}
else if (durationSeconds > 0 && durationNanos < 0)
{
durationSeconds -= 1;
durationNanos = (int)(durationNanos + NanosPerSecond);
}
return Duration.Create(durationSeconds, durationNanos);
}
/// <inheritdoc />
public int CompareTo(Timestamp other)
{
int cmp = (this.Seconds < other.Seconds) ? -1 : ((this.Seconds > other.Seconds) ? 1 : 0);
if (cmp != 0)
{
return cmp;
}
return (this.Nanos < other.Nanos) ? -1 : ((this.Nanos > other.Nanos) ? 1 : 0);
}
/// <inheritdoc />
public int CompareTo(object obj)
{
if (obj is Timestamp timestamp)
{
return this.CompareTo(timestamp);
}
else
{
throw new InvalidOperationException();
}
}
/// <inheritdoc/>
public override string ToString()
{
return "Timestamp{"
+ "seconds=" + this.Seconds + ", "
+ "nanos=" + this.Nanos
+ "}";
}
/// <inheritdoc/>
public override bool Equals(object o)
{
if (o is Timestamp that)
{
return (this.Seconds == that.Seconds)
&& (this.Nanos == that.Nanos);
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
long h = 1;
h *= 1000003;
h ^= (this.Seconds >> 32) ^ this.Seconds;
h *= 1000003;
h ^= this.Nanos;
return (int)h;
}
private static Timestamp OfSecond(long seconds, long nanoAdjustment)
{
long floor = (long)Math.Floor((double)nanoAdjustment / NanosPerSecond);
long secs = seconds + floor;
long nos = nanoAdjustment - (floor * NanosPerSecond);
return Create(secs, (int)nos);
}
private Timestamp Plus(long secondsToAdd, long nanosToAdd)
{
if ((secondsToAdd | nanosToAdd) == 0)
{
return this;
}
long sec = this.Seconds + secondsToAdd;
long nanoSeconds = Math.DivRem(nanosToAdd, NanosPerSecond, out long nanosSpill);
sec += nanoSeconds;
long nanoAdjustment = this.Nanos + nanosSpill;
return OfSecond(sec, nanoAdjustment);
}
}
}

View File

@ -0,0 +1,30 @@
// <copyright file="IEventQueue.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Internal
{
/// <summary>
/// Event queue abstraction.
/// </summary>
public interface IEventQueue
{
/// <summary>
/// Queues a single entry.
/// </summary>
/// <param name="entry">Entry to be queued.</param>
void Enqueue(IEventQueueEntry entry);
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="IEventQueueEntry.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Internal
{
/// <summary>
/// Queue entry abstraction.
/// </summary>
public interface IEventQueueEntry
{
/// <summary>
/// Method process will be called when queue entry needs to be processed.
/// </summary>
void Process();
}
}

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))\build\Common.prod.props" />
<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) != 'Windows_NT'">netstandard2.0</TargetFrameworks>
<Description>OpenCensus .NET API abstractions</Description>
<IncludeSymbols>True</IncludeSymbols>
<PackageTags>Tracing;OpenCensus;Management;Monitoring</PackageTags>
<PackageIconUrl>https://opencensus.io/images/opencensus-logo.png</PackageIconUrl>
<PackageProjectUrl>https://opencensus.io</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Authors>OpenCensus authors</Authors>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RootNamespace>OpenCensus</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))/build/OpenCensus.prod.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Stats\" />
<Folder Include="Tags\" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Utils\AttributesWithCapacity.cs" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,36 @@
// <copyright file="AssemblyInfo.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System.Runtime.CompilerServices;
[assembly: System.CLSCompliant(true)]
[assembly: InternalsVisibleTo("OpenCensus.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)]
#if SIGNED
internal static class AssemblyInfo
{
public const string PublicKey = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010051C1562A090FB0C9F391012A32198B5E5D9A60E9B80FA2D7B434C9E5CCB7259BD606E66F9660676AFC6692B8CDC6793D190904551D2103B7B22FA636DCBB8208839785BA402EA08FC00C8F1500CCEF28BBF599AA64FFB1E1D5DC1BF3420A3777BADFE697856E9D52070A50C3EA5821C80BEF17CA3ACFFA28F89DD413F096F898";
public const string MoqPublicKey = ", PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7";
}
#else
internal static class AssemblyInfo
{
public const string PublicKey = "";
public const string MoqPublicKey = "";
}
#endif

View File

@ -0,0 +1,40 @@
// <copyright file="IResource.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Resources
{
using System.Collections.Generic;
using OpenCensus.Tags;
/// <summary>
/// Represents a resource, which captures identifying information about the entities
/// for which signals(stats or traces) are reported. It further provides a framework for detection
/// of resource information from the environment and progressive population as signals propagate from
/// the core instrumentation library to a backend's exporter.
/// </summary>
public interface IResource
{
/// <summary>
/// Gets Type identifier for the resource.
/// </summary>
string Type { get; }
/// <summary>
/// Gets the map of the labels/tags that describe the resource.
/// </summary>
IEnumerable<ITag> Tags { get; }
}
}

View File

@ -0,0 +1,25 @@
// <copyright file="ICount.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Count aggregation.
/// </summary>
public interface ICount : IAggregation
{
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ICountData.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Data accumulated by Count aggregation.
/// </summary>
public interface ICountData : IAggregationData
{
/// <summary>
/// Gets the counter representing the result of an aggregation.
/// </summary>
long Count { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="IDistribution.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Distribution aggregation.
/// </summary>
public interface IDistribution : IAggregation
{
/// <summary>
/// Gets the configuration for distribution aggregation - distribution bucket boundaries.
/// </summary>
IBucketBoundaries BucketBoundaries { get; }
}
}

View File

@ -0,0 +1,56 @@
// <copyright file="IDistributionData.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
using System.Collections.Generic;
/// <summary>
/// Data accumulated by distributed aggregation.
/// </summary>
public interface IDistributionData : IAggregationData
{
/// <summary>
/// Gets the mean of values.
/// </summary>
double Mean { get; }
/// <summary>
/// Gets the number of samples.
/// </summary>
long Count { get; }
/// <summary>
/// Gets the minimum of values.
/// </summary>
double Min { get; }
/// <summary>
/// Gets the maximum of values.
/// </summary>
double Max { get; }
/// <summary>
/// Gets the sum of squares of values.
/// </summary>
double SumOfSquaredDeviations { get; }
/// <summary>
/// Gets the counts in buckets.
/// </summary>
IReadOnlyList<long> BucketCounts { get; }
}
}

View File

@ -0,0 +1,25 @@
// <copyright file="ILastValue.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Last value aggregation.
/// </summary>
public interface ILastValue : IAggregation
{
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ILastValueDataDouble.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Data accumulated by the last value aggregation amongst double values.
/// </summary>
public interface ILastValueDataDouble : IAggregationData
{
/// <summary>
/// Gets the last value as a double.
/// </summary>
double LastValue { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ILastValueDataLong.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Data accumulated by the last value aggregator amongst long values.
/// </summary>
public interface ILastValueDataLong : IAggregationData
{
/// <summary>
/// Gets the last value as a long value.
/// </summary>
long LastValue { get; }
}
}

View File

@ -0,0 +1,25 @@
// <copyright file="IMean.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Mean aggregation.
/// </summary>
public interface IMean : IAggregation
{
}
}

View File

@ -0,0 +1,44 @@
// <copyright file="IMeanData.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Data accumulated by mean value aggregator.
/// </summary>
public interface IMeanData : IAggregationData
{
/// <summary>
/// Gets the mean value.
/// </summary>
double Mean { get; }
/// <summary>
/// Gets the count of samples.
/// </summary>
long Count { get; }
/// <summary>
/// Gets the maximum value.
/// </summary>
double Max { get; }
/// <summary>
/// Gets the minimum value.
/// </summary>
double Min { get; }
}
}

View File

@ -0,0 +1,25 @@
// <copyright file="ISum.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Sum aggregation.
/// </summary>
public interface ISum : IAggregation
{
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ISumDataDouble.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Data accumulated by the sum aggregator amongst double values.
/// </summary>
public interface ISumDataDouble : IAggregationData
{
/// <summary>
/// Gets the sum of values as double.
/// </summary>
double Sum { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ISumDataLong.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Aggregations
{
/// <summary>
/// Data aggregated by sum aggregator amongst long values.
/// </summary>
public interface ISumDataLong : IAggregationData
{
/// <summary>
/// Gets the sum of values as a long.
/// </summary>
long Sum { get; }
}
}

View File

@ -0,0 +1,46 @@
// <copyright file="IAggregation.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System;
using OpenCensus.Stats.Aggregations;
/// <summary>
/// Represents the type of aggregation.
/// </summary>
public interface IAggregation
{
/// <summary>
/// Executed callback specific to aggregation without type casting.
/// </summary>
/// <typeparam name="T">Expected return value.</typeparam>
/// <param name="p0">Callback to be called by sum aggregation.</param>
/// <param name="p1">Callback to be called by count aggregation.</param>
/// <param name="p2">Callback to be called by mean aggregation.</param>
/// <param name="p3">Callback to be called by distribution aggregation.</param>
/// <param name="p4">Callback to be called by last value aggregation.</param>
/// <param name="p6">Callback to be called for any other aggregation.</param>
/// <returns>The result of the aggregator-specific callback execution.</returns>
T Match<T>(
Func<ISum, T> p0,
Func<ICount, T> p1,
Func<IMean, T> p2,
Func<IDistribution, T> p3,
Func<ILastValue, T> p4,
Func<IAggregation, T> p6);
}
}

View File

@ -0,0 +1,50 @@
// <copyright file="IAggregationData.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System;
using OpenCensus.Stats.Aggregations;
/// <summary>
/// Gets the aggregation data.
/// </summary>
public interface IAggregationData
{
/// <summary>
/// Executes aggregation data specific callback without type casting.
/// </summary>
/// <typeparam name="T">Callback result type.</typeparam>
/// <param name="p0">Callback for the double sum data.</param>
/// <param name="p1">Callback for the long sum data.</param>
/// <param name="p2">Callback for the count data.</param>
/// <param name="p3">Callback for the mean data.</param>
/// <param name="p4">Callback for the distribution data.</param>
/// <param name="p5">Callback for the double last value data.</param>
/// <param name="p6">Callback for the long last value data.</param>
/// <param name="defaultFunction">Callback for any other data.</param>
/// <returns>Callback executuion result.</returns>
T Match<T>(
Func<ISumDataDouble, T> p0,
Func<ISumDataLong, T> p1,
Func<ICountData, T> p2,
Func<IMeanData, T> p3,
Func<IDistributionData, T> p4,
Func<ILastValueDataDouble, T> p5,
Func<ILastValueDataLong, T> p6,
Func<IAggregationData, T> defaultFunction);
}
}

View File

@ -0,0 +1,31 @@
// <copyright file="IBucketBoundaries.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System.Collections.Generic;
/// <summary>
/// Bucket boundaries for the distribution aggregator.
/// </summary>
public interface IBucketBoundaries
{
/// <summary>
/// Gets the list of boundaries for the distribution aggregator.
/// </summary>
IReadOnlyList<double> Boundaries { get; }
}
}

View File

@ -0,0 +1,55 @@
// <copyright file="IMeasure.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System;
using OpenCensus.Stats.Measures;
/// <summary>
/// A single measure to track.
/// </summary>
public interface IMeasure
{
/// <summary>
/// Gets the name of the measure.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the description of the measure.
/// </summary>
string Description { get; }
/// <summary>
/// Gets the unit of the measure.
/// </summary>
string Unit { get; }
/// <summary>
/// Execute callback with the specific measure type without type casting.
/// </summary>
/// <typeparam name="T">The result type of a callback.</typeparam>
/// <param name="p0">Callback to be called for the double measure.</param>
/// <param name="p1">Callback to be called for the long measure.</param>
/// <param name="defaultFunction">Callback to be called for any other measure.</param>
/// <returns>The result of measure type specific callback execution.</returns>
T Match<T>(
Func<IMeasureDouble, T> p0,
Func<IMeasureLong, T> p1,
Func<IMeasure, T> defaultFunction);
}
}

View File

@ -0,0 +1,54 @@
// <copyright file="IMeasureMap.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using OpenCensus.Stats.Measures;
using OpenCensus.Tags;
/// <summary>
/// Measure map. Holds the mapping of measures and values.
/// </summary>
public interface IMeasureMap
{
/// <summary>
/// Associates the measure with the given value. Subsequent updates to the same measure will overwrite the previous value.
/// </summary>
/// <param name="measure">Measure to associate the value with.</param>
/// <param name="value">Value to associate with the measure.</param>
/// <returns>Measure map for calls chaining.</returns>
IMeasureMap Put(IMeasureDouble measure, double value);
/// <summary>
/// Associates the measure with the given value. Subsequent updates to the same measure will overwrite the previous value.
/// </summary>
/// <param name="measure">Measure to associate the value with.</param>
/// <param name="value">Value to associate with the measure.</param>
/// <returns>Measure map for calls chaining.</returns>
IMeasureMap Put(IMeasureLong measure, long value);
/// <summary>
/// Records all of the measures at the same time with the current tag context.
/// </summary>
void Record();
/// <summary>
/// Records all of the measures at the same time with the explicit tag context.
/// </summary>
/// <param name="tags">Tags to associate with the measure.</param>
void Record(ITagContext tags);
}
}

View File

@ -0,0 +1,42 @@
// <copyright file="IMeasurement.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System;
using OpenCensus.Stats.Measurements;
/// <summary>
/// Represents a single measurement for a measure.
/// </summary>
public interface IMeasurement
{
/// <summary>
/// Gets the measure this measurement recorded for.
/// </summary>
IMeasure Measure { get; }
/// <summary>
/// Calls the measure-type specific callback without type casting of a measurement.
/// </summary>
/// <typeparam name="T">Result type of the callback.</typeparam>
/// <param name="p0">Callback to be called for double measure.</param>
/// <param name="p1">Callback to be called for long measure.</param>
/// <param name="defaultFunction">Callback to be called for all other measures.</param>
/// <returns>The result of measure type specific callback execution.</returns>
T Match<T>(Func<IMeasurementDouble, T> p0, Func<IMeasurementLong, T> p1, Func<IMeasurement, T> defaultFunction);
}
}

View File

@ -0,0 +1,39 @@
// <copyright file="IStatsComponent.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
/// <summary>
/// Stats recording configuration.
/// </summary>
public interface IStatsComponent
{
/// <summary>
/// Gets the view manager that holds current set of aggregators.
/// </summary>
IViewManager ViewManager { get; }
/// <summary>
/// Gets the stats recorder to record values to.
/// </summary>
IStatsRecorder StatsRecorder { get; }
/// <summary>
/// Gets the state of the state collection.
/// </summary>
StatsCollectionState State { get; }
}
}

View File

@ -0,0 +1,30 @@
// <copyright file="IStatsRecorder.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
/// <summary>
/// Stats recorder. Used to supply and record new measurements.
/// </summary>
public interface IStatsRecorder
{
/// <summary>
/// Returns the measure map to record values to.
/// </summary>
/// <returns>Measure maps to record values to.</returns>
IMeasureMap NewMeasureMap();
}
}

View File

@ -0,0 +1,52 @@
// <copyright file="IView.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System.Collections.Generic;
using OpenCensus.Tags;
/// <summary>
/// Stats recording view.
/// </summary>
public interface IView
{
/// <summary>
/// Gets the name of the view.
/// </summary>
IViewName Name { get; }
/// <summary>
/// Gets the description of the view.
/// </summary>
string Description { get; }
/// <summary>
/// Gets the measure this view record values for.
/// </summary>
IMeasure Measure { get; }
/// <summary>
/// Gets the aggregation is used by this view.
/// </summary>
IAggregation Aggregation { get; }
/// <summary>
/// Gets the columns (dimensions) recorded by this view.
/// </summary>
IReadOnlyList<ITagKey> Columns { get; }
}
}

View File

@ -0,0 +1,48 @@
// <copyright file="IViewData.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System;
using System.Collections.Generic;
using OpenCensus.Tags;
/// <summary>
/// Result data of the view aggregation.
/// </summary>
public interface IViewData
{
/// <summary>
/// Gets the view this data calculated for.
/// </summary>
IView View { get; }
/// <summary>
/// Gets the aggregation data grouped by combination of tag values associated with this view data.
/// </summary>
IDictionary<TagValues, IAggregationData> AggregationMap { get; }
/// <summary>
/// Gets the timestamp of a start of this aggregation.
/// </summary>
DateTimeOffset Start { get; }
/// <summary>
/// Gets the timestamp of the end of this aggregation.
/// </summary>
DateTimeOffset End { get; }
}
}

View File

@ -0,0 +1,44 @@
// <copyright file="IViewManager.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
using System.Collections.Generic;
/// <summary>
/// View manager that holds all configured views.
/// </summary>
public interface IViewManager
{
/// <summary>
/// Gets all configured views.
/// </summary>
ISet<IView> AllExportedViews { get; }
/// <summary>
/// Returns the view with specified view name.
/// </summary>
/// <param name="view">View name.</param>
/// <returns>The view with the specified name.</returns>
IViewData GetView(IViewName view);
/// <summary>
/// Registers a new view to be tracked.
/// </summary>
/// <param name="view">View to be registered.</param>
void RegisterView(IView view);
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="IViewName.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
/// <summary>
/// View name.
/// </summary>
public interface IViewName
{
/// <summary>
/// Gets the string representation of the view name.
/// </summary>
string AsString { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="IMeasurementDouble.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Measurements
{
/// <summary>
/// Represents a single measurment for aggregation as double.
/// </summary>
public interface IMeasurementDouble : IMeasurement
{
/// <summary>
/// Gets the long value for aggregation as double.
/// </summary>
double Value { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="IMeasurementLong.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Measurements
{
/// <summary>
/// Represents a single measurement for aggregation as a long.
/// </summary>
public interface IMeasurementLong : IMeasurement
{
/// <summary>
/// Gets the long value to be aggregated.
/// </summary>
long Value { get; }
}
}

View File

@ -0,0 +1,25 @@
// <copyright file="IMeasureDouble.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Measures
{
/// <summary>
/// Represents a measure to use in aggregations for double values.
/// </summary>
public interface IMeasureDouble : IMeasure
{
}
}

View File

@ -0,0 +1,25 @@
// <copyright file="IMeasureLong.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats.Measures
{
/// <summary>
/// Represents a measure to use in aggregations for long values.
/// </summary>
public interface IMeasureLong : IMeasure
{
}
}

View File

@ -0,0 +1,34 @@
// <copyright file="StatsCollectionState.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Stats
{
/// <summary>
/// Stats collection state.
/// </summary>
public enum StatsCollectionState
{
/// <summary>
/// Collection is enabled.
/// </summary>
ENABLED,
/// <summary>
/// Collection is disabled.
/// </summary>
DISABLED,
}
}

View File

@ -0,0 +1,34 @@
// <copyright file="ITag.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
/// <summary>
/// Tag with the key and value.
/// </summary>
public interface ITag
{
/// <summary>
/// Gets the tag key.
/// </summary>
ITagKey Key { get; }
/// <summary>
/// Gets the tag value.
/// </summary>
ITagValue Value { get; }
}
}

View File

@ -0,0 +1,27 @@
// <copyright file="ITagContext.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
using System.Collections.Generic;
/// <summary>
/// Collection of tags representing the tags context.
/// </summary>
public interface ITagContext : IEnumerable<ITag>
{
}
}

View File

@ -0,0 +1,53 @@
// <copyright file="ITagContextBuilder.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
using OpenCensus.Common;
/// <summary>
/// Tags context builder.
/// </summary>
public interface ITagContextBuilder
{
/// <summary>
/// Puts a new tag into context.
/// </summary>
/// <param name="key">Key of the tag to add.</param>
/// <param name="value">Value of the tag to add.</param>
/// <returns>Tag context builder for operations chaining.</returns>
ITagContextBuilder Put(ITagKey key, ITagValue value);
/// <summary>
/// Removes tag with the given key from the context.
/// </summary>
/// <param name="key">Key of the tag to remove.</param>
/// <returns>Tag context builder for operations chaining.</returns>
ITagContextBuilder Remove(ITagKey key);
/// <summary>
/// Builds the tags context.
/// </summary>
/// <returns>Resulting tag context.</returns>
ITagContext Build();
/// <summary>
/// Builds tag context and save it as current.
/// </summary>
/// <returns>Scope control object. Dispose it to close a scope.</returns>
IScope BuildScoped();
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ITagKey.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
/// <summary>
/// Tag key.
/// </summary>
public interface ITagKey
{
/// <summary>
/// Gets the name of the key.
/// </summary>
string Name { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ITagValue.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
/// <summary>
/// Tag value.
/// </summary>
public interface ITagValue
{
/// <summary>
/// Gets tag value as string.
/// </summary>
string AsString { get; }
}
}

View File

@ -0,0 +1,62 @@
// <copyright file="ITagger.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
using OpenCensus.Common;
/// <summary>
/// Tags API configuraiton.
/// </summary>
public interface ITagger
{
/// <summary>
/// Gets the empty tags context.
/// </summary>
ITagContext Empty { get; }
/// <summary>
/// Gets the current tags context.
/// </summary>
ITagContext CurrentTagContext { get; }
/// <summary>
/// Gets the empty tags builder.
/// </summary>
ITagContextBuilder EmptyBuilder { get; }
/// <summary>
/// Gets the builder out of current context.
/// </summary>
ITagContextBuilder CurrentBuilder { get; }
/// <summary>
/// Enters the scope of code where the given tag context is in the current context and
/// returns an object that represents that scope.The scope is exited when the returned object is
/// closed.
/// </summary>
/// <param name="tags">Tags to set as current.</param>
/// <returns>Scope object. Dispose to dissassociate tags context from the current context.</returns>
IScope WithTagContext(ITagContext tags);
/// <summary>
/// Gets the builder from the tags context.
/// </summary>
/// <param name="tags">Tags to pre-initialize builder with.</param>
/// <returns>Tags context builder preinitialized with the given tags.</returns>
ITagContextBuilder ToBuilder(ITagContext tags);
}
}

View File

@ -0,0 +1,41 @@
// <copyright file="ITagsComponent.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
using OpenCensus.Tags.Propagation;
/// <summary>
/// Tagger configuration.
/// </summary>
public interface ITagsComponent
{
/// <summary>
/// Gets the tagger to operate with tags.
/// </summary>
ITagger Tagger { get; }
/// <summary>
/// Gets the propagation component to use to serialize and deserialize tags on the wire.
/// </summary>
ITagPropagationComponent TagPropagationComponent { get; }
/// <summary>
/// Gets the state of tagging API - enabled or disabled.
/// </summary>
TaggingState State { get; }
}
}

View File

@ -0,0 +1,38 @@
// <copyright file="ITagContextBinarySerializer.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags.Propagation
{
/// <summary>
/// Binary serializer and deserializer of tags.
/// </summary>
public interface ITagContextBinarySerializer
{
/// <summary>
/// Converts tags into byte array.
/// </summary>
/// <param name="tags">Tags to serialize.</param>
/// <returns>Binary representation of tags.</returns>
byte[] ToByteArray(ITagContext tags);
/// <summary>
/// Deserialize tags from byte array.
/// </summary>
/// <param name="bytes">Bytes to deserialize.</param>
/// <returns>Tags deserialized from bytes.</returns>
ITagContext FromByteArray(byte[] bytes);
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="ITagPropagationComponent.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags.Propagation
{
/// <summary>
/// Stores configuration of various propagation serializers for tags.
/// </summary>
public interface ITagPropagationComponent
{
/// <summary>
/// Gets binary serializer/deserializer for tags.
/// </summary>
ITagContextBinarySerializer BinarySerializer { get; }
}
}

View File

@ -0,0 +1,110 @@
// <copyright file="TagValues.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
using System.Collections.Generic;
using OpenCensus.Abstractions.Utils;
/// <summary>
/// Collection of tags.
/// </summary>
public sealed class TagValues
{
private TagValues(IReadOnlyList<ITagValue> values)
{
this.Values = values;
}
/// <summary>
/// Gets the collection of tag values.
/// </summary>
public IReadOnlyList<ITagValue> Values { get; }
/// <summary>
/// Create tag values out of list of tags.
/// </summary>
/// <param name="values">Values to create tag values from.</param>
/// <returns>Resulting tag values collection.</returns>
public static TagValues Create(IReadOnlyList<ITagValue> values)
{
return new TagValues(values);
}
/// <inheritdoc/>
public override string ToString()
{
return "TagValues{"
+ "values=" + Collections.ToString(this.Values)
+ "}";
}
/// <inheritdoc/>
public override bool Equals(object o)
{
if (o == this)
{
return true;
}
if (o is TagValues that)
{
if (this.Values.Count != that.Values.Count)
{
return false;
}
for (int i = 0; i < this.Values.Count; i++)
{
if (this.Values[i] == null)
{
if (that.Values[i] != null)
{
return false;
}
}
else
{
if (!this.Values[i].Equals(that.Values[i]))
{
return false;
}
}
}
return true;
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
int h = 1;
h *= 1000003;
foreach (var v in this.Values)
{
if (v != null)
{
h ^= v.GetHashCode();
}
}
return h;
}
}
}

View File

@ -0,0 +1,34 @@
// <copyright file="TaggingState.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Tags
{
/// <summary>
/// State of tagging API.
/// </summary>
public enum TaggingState
{
/// <summary>
/// Tagging enabled.
/// </summary>
ENABLED,
/// <summary>
/// Tagging disabled.
/// </summary>
DISABLED,
}
}

View File

@ -0,0 +1,93 @@
// <copyright file="Annotation.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using OpenCensus.Abstractions.Utils;
public sealed class Annotation : IAnnotation
{
private static readonly ReadOnlyDictionary<string, IAttributeValue> EmptyAttributes =
new ReadOnlyDictionary<string, IAttributeValue>(new Dictionary<string, IAttributeValue>());
internal Annotation(string description, IDictionary<string, IAttributeValue> attributes)
{
this.Description = description ?? throw new ArgumentNullException("Null description");
this.Attributes = attributes ?? throw new ArgumentNullException("Null attributes");
}
public string Description { get; }
public IDictionary<string, IAttributeValue> Attributes { get; }
public static IAnnotation FromDescription(string description)
{
return new Annotation(description, EmptyAttributes);
}
public static IAnnotation FromDescriptionAndAttributes(string description, IDictionary<string, IAttributeValue> attributes)
{
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
IDictionary<string, IAttributeValue> readOnly = new ReadOnlyDictionary<string, IAttributeValue>(attributes);
return new Annotation(description, readOnly);
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj == this)
{
return true;
}
if (obj is Annotation annotation)
{
return this.Description.Equals(annotation.Description) &&
this.Attributes.SequenceEqual(annotation.Attributes);
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
int h = 1;
h *= 1000003;
h ^= this.Description.GetHashCode();
h *= 1000003;
h ^= this.Attributes.GetHashCode();
return h;
}
/// <inheritdoc/>
public override string ToString()
{
return "Annotation{"
+ "description=" + this.Description + ", "
+ "attributes=" + Collections.ToString(this.Attributes)
+ "}";
}
}
}

View File

@ -0,0 +1,83 @@
// <copyright file="AttributeValue.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace
{
using System;
/// <summary>
/// Attribute value.
/// </summary>
public abstract class AttributeValue : IAttributeValue
{
internal AttributeValue()
{
}
/// <summary>
/// Creates string attribute value from value provided.
/// </summary>
/// <param name="stringValue">String value.</param>
/// <returns>Attribute value encapsulating the provided string value.</returns>
public static IAttributeValue<string> StringAttributeValue(string stringValue)
{
if (stringValue == null)
{
throw new ArgumentNullException(nameof(stringValue));
}
return new AttributeValue<string>(stringValue);
}
/// <summary>
/// Creates long attribute value from value provided.
/// </summary>
/// <param name="longValue">Long value.</param>
/// <returns>Attribute value encapsulating the provided long value.</returns>
public static IAttributeValue<long> LongAttributeValue(long longValue)
{
return new AttributeValue<long>(longValue);
}
/// <summary>
/// Creates boolean attribute value from value provided.
/// </summary>
/// <param name="booleanValue">Boolean value.</param>
/// <returns>Attribute value encapsulating the provided boolean value.</returns>
public static IAttributeValue<bool> BooleanAttributeValue(bool booleanValue)
{
return new AttributeValue<bool>(booleanValue);
}
/// <summary>
/// Creates double attribute value from value provided.
/// </summary>
/// <param name="doubleValue">Double value.</param>
/// <returns>Attribute value encapsulating the provided double value.</returns>
public static IAttributeValue<double> DoubleAttributeValue(double doubleValue)
{
return new AttributeValue<double>(doubleValue);
}
/// <inheritdoc/>
public abstract T Match<T>(
Func<string, T> stringFunction,
Func<bool, T> booleanFunction,
Func<long, T> longFunction,
Func<double, T> doubleFunction,
Func<object, T> defaultFunction);
}
}

View File

@ -0,0 +1,145 @@
// <copyright file="CanonicalCode.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace
{
/// <summary>
/// Canonical result code of span execution.
/// </summary>
public enum CanonicalCode
{
/// <summary>
/// The operation completed successfully.
/// </summary>
Ok = 0,
/// <summary>
/// The operation was cancelled (typically by the caller).
/// </summary>
Cancelled = 1,
/// <summary>
/// Unknown error. An example of where this error may be returned is if a Status value received
/// from another address space belongs to an error-space that is not known in this address space.
/// Also errors raised by APIs that do not return enough error information may be converted to
/// this error.
/// </summary>
Unknown = 2,
/// <summary>
/// Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION.
/// INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the
/// system (e.g., a malformed file name).
/// </summary>
InvalidArgument = 3,
/// <summary>
/// Deadline expired before operation could complete. For operations that change the state of the
/// system, this error may be returned even if the operation has completed successfully. For
/// example, a successful response from a server could have been delayed long enough for the
/// deadline to expire.
/// </summary>
DeadlineExceeded = 4,
/// <summary>
/// Some requested entity (e.g., file or directory) was not found.
/// </summary>
NotFound = 5,
/// <summary>
/// Some entity that we attempted to create (e.g., file or directory) already exists.
/// </summary>
AlreadyExists = 6,
/// <summary>
/// The caller does not have permission to execute the specified operation. PERMISSION_DENIED
/// must not be used for rejections caused by exhausting some resource (use RESOURCE_EXHAUSTED
/// instead for those errors). PERMISSION_DENIED must not be used if the caller cannot be
/// identified (use UNAUTHENTICATED instead for those errors).
/// </summary>
PermissionDenied = 7,
/// <summary>
/// Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system
/// is out of space.
/// </summary>
ResourceExhausted = 8,
/// <summary>
/// Operation was rejected because the system is not in a state required for the operation's
/// execution. For example, directory to be deleted may be non-empty, an rmdir operation is
/// applied to a non-directory, etc.
/// A litmus test that may help a service implementor in deciding between FAILED_PRECONDITION,
/// ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the client can retry just the failing call.
/// (b) Use ABORTED if the client should retry at a higher-level (e.g., restarting a
/// read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client should not retry until
/// the system state has been explicitly fixed. E.g., if an "rmdir" fails because the directory
/// is non-empty, FAILED_PRECONDITION should be returned since the client should not retry unless
/// they have first fixed up the directory by deleting files from it.
/// </summary>
FailedPrecondition = 9,
/// <summary>
/// The operation was aborted, typically due to a concurrency issue like sequencer check
/// failures, transaction aborts, etc.
/// </summary>
Aborted = 10,
/// <summary>
/// Operation was attempted past the valid range. E.g., seeking or reading past end of file.
///
/// Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system
/// state changes. For example, a 32-bit file system will generate INVALID_ARGUMENT if asked to
/// read at an offset that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if
/// asked to read from an offset past the current file size.
///
/// There is a fair bit of overlap between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend
/// using OUT_OF_RANGE (the more specific error) when it applies so that callers who are
/// iterating through a space can easily look for an OUT_OF_RANGE error to detect when they are
/// done.
/// </summary>
OutOfRange = 11,
/// <summary>
/// Operation is not implemented or not supported/enabled in this service.
/// </summary>
Unimplemented = 12,
/// <summary>
/// Internal errors. Means some invariants expected by underlying system has been broken. If you
/// see one of these errors, something is very broken.
/// </summary>
Internal = 13,
/// <summary>
/// The service is currently unavailable. This is a most likely a transient condition and may be
/// corrected by retrying with a backoff.
///
/// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE.
/// </summary>
Unavailable = 14,
/// <summary>
/// Unrecoverable data loss or corruption.
/// </summary>
DataLoss = 15,
/// <summary>
/// The request does not have valid authentication credentials for the operation.
/// </summary>
Unauthenticated = 16,
}
}

View File

@ -0,0 +1,35 @@
// <copyright file="ITraceConfig.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Config
{
/// <summary>
/// Trace configuration.
/// </summary>
public interface ITraceConfig
{
/// <summary>
/// Gets ths active trace parameters that can be updated in runtime.
/// </summary>
ITraceParams ActiveTraceParams { get; }
/// <summary>
/// Updates the active trace parameters.
/// </summary>
/// <param name="traceParams">New trace parameters to use.</param>
void UpdateActiveTraceParams(ITraceParams traceParams);
}
}

View File

@ -0,0 +1,55 @@
// <copyright file="ITraceParams.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Config
{
/// <summary>
/// Trace parameters that can be updates in runtime.
/// </summary>
public interface ITraceParams
{
/// <summary>
/// Gets the sampler.
/// </summary>
ISampler Sampler { get; }
/// <summary>
/// Gets the maximum number of attributes on span.
/// </summary>
int MaxNumberOfAttributes { get; }
/// <summary>
/// Gets that maximum Number of annotations on span.
/// </summary>
int MaxNumberOfAnnotations { get; }
/// <summary>
/// Gets the maximum number of messages on span.
/// </summary>
int MaxNumberOfMessageEvents { get; }
/// <summary>
/// Gets the maximum number of links on span.
/// </summary>
int MaxNumberOfLinks { get; }
/// <summary>
/// Creates params builder preinitialized with the trace parameters supplied.
/// </summary>
/// <returns>Trace parameters builder.</returns>
TraceParamsBuilder ToBuilder();
}
}

View File

@ -0,0 +1,136 @@
// <copyright file="TraceParams.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Config
{
using System;
using OpenCensus.Trace.Sampler;
/// <inheritdoc/>
public sealed class TraceParams : ITraceParams
{
/// <summary>
/// Default trace parameters.
/// </summary>
public static readonly ITraceParams Default =
new TraceParams(Samplers.GetProbabilitySampler(DefaultProbability), DefaultSpanMaxNumAttributes, DefaultSpanMaxNumAnnotations, DefaultSpanMaxNumMessageEvents, DefaultSpanMaxNumLinks);
private const double DefaultProbability = 1e-4;
private const int DefaultSpanMaxNumAttributes = 32;
private const int DefaultSpanMaxNumAnnotations = 32;
private const int DefaultSpanMaxNumMessageEvents = 128;
private const int DefaultSpanMaxNumLinks = 128;
internal TraceParams(ISampler sampler, int maxNumberOfAttributes, int maxNumberOfAnnotations, int maxNumberOfMessageEvents, int maxNumberOfLinks)
{
if (maxNumberOfAttributes <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxNumberOfAttributes));
}
if (maxNumberOfAnnotations <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxNumberOfAnnotations));
}
if (maxNumberOfMessageEvents <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxNumberOfMessageEvents));
}
if (maxNumberOfLinks <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxNumberOfLinks));
}
this.Sampler = sampler ?? throw new ArgumentNullException(nameof(sampler));
this.MaxNumberOfAttributes = maxNumberOfAttributes;
this.MaxNumberOfAnnotations = maxNumberOfAnnotations;
this.MaxNumberOfMessageEvents = maxNumberOfMessageEvents;
this.MaxNumberOfLinks = maxNumberOfLinks;
}
/// <inheritdoc/>
public ISampler Sampler { get; }
/// <inheritdoc/>
public int MaxNumberOfAttributes { get; }
/// <inheritdoc/>
public int MaxNumberOfAnnotations { get; }
/// <inheritdoc/>
public int MaxNumberOfMessageEvents { get; }
/// <inheritdoc/>
public int MaxNumberOfLinks { get; }
/// <inheritdoc/>
public TraceParamsBuilder ToBuilder()
{
return new TraceParamsBuilder(this);
}
/// <inheritdoc/>
public override string ToString()
{
return "TraceParams{"
+ "sampler=" + this.Sampler + ", "
+ "maxNumberOfAttributes=" + this.MaxNumberOfAttributes + ", "
+ "maxNumberOfAnnotations=" + this.MaxNumberOfAnnotations + ", "
+ "maxNumberOfMessageEvents=" + this.MaxNumberOfMessageEvents + ", "
+ "maxNumberOfLinks=" + this.MaxNumberOfLinks
+ "}";
}
/// <inheritdoc/>
public override bool Equals(object o)
{
if (o == this)
{
return true;
}
if (o is TraceParams that)
{
return this.Sampler.Equals(that.Sampler)
&& (this.MaxNumberOfAttributes == that.MaxNumberOfAttributes)
&& (this.MaxNumberOfAnnotations == that.MaxNumberOfAnnotations)
&& (this.MaxNumberOfMessageEvents == that.MaxNumberOfMessageEvents)
&& (this.MaxNumberOfLinks == that.MaxNumberOfLinks);
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
int h = 1;
h *= 1000003;
h ^= this.Sampler.GetHashCode();
h *= 1000003;
h ^= this.MaxNumberOfAttributes;
h *= 1000003;
h ^= this.MaxNumberOfAnnotations;
h *= 1000003;
h ^= this.MaxNumberOfMessageEvents;
h *= 1000003;
h ^= this.MaxNumberOfLinks;
return h;
}
}
}

View File

@ -0,0 +1,141 @@
// <copyright file="TraceParamsBuilder.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Config
{
using System;
/// <summary>
/// Trace parameters builder.
/// </summary>
public sealed class TraceParamsBuilder
{
private ISampler sampler;
private int? maxNumberOfAttributes;
private int? maxNumberOfAnnotations;
private int? maxNumberOfMessageEvents;
private int? maxNumberOfLinks;
internal TraceParamsBuilder(TraceParams source)
{
this.sampler = source.Sampler;
this.maxNumberOfAttributes = source.MaxNumberOfAttributes;
this.maxNumberOfAnnotations = source.MaxNumberOfAnnotations;
this.maxNumberOfMessageEvents = source.MaxNumberOfMessageEvents;
this.maxNumberOfLinks = source.MaxNumberOfLinks;
}
/// <summary>
/// Sets sempler to use.
/// </summary>
/// <param name="sampler">Sampler to use.</param>
/// <returns>Builder to chain operations.</returns>
public TraceParamsBuilder SetSampler(ISampler sampler)
{
this.sampler = sampler ?? throw new ArgumentNullException("Null sampler");
return this;
}
/// <summary>
/// Sets the maximum number of attributes.
/// </summary>
/// <param name="maxNumberOfAttributes">Maximum number of attributes per span.</param>
/// <returns>Builder to chain operations.</returns>
public TraceParamsBuilder SetMaxNumberOfAttributes(int maxNumberOfAttributes)
{
this.maxNumberOfAttributes = maxNumberOfAttributes;
return this;
}
/// <summary>
/// Sets the maximum number of annotations.
/// </summary>
/// <param name="maxNumberOfAnnotations">Maximum number of annotations per span.</param>
/// <returns>Builder to chain operations.</returns>
public TraceParamsBuilder SetMaxNumberOfAnnotations(int maxNumberOfAnnotations)
{
this.maxNumberOfAnnotations = maxNumberOfAnnotations;
return this;
}
/// <summary>
/// Sets the maximum number of message events on span.
/// </summary>
/// <param name="maxNumberOfMessageEvents">Maximum number of message events per span.</param>
/// <returns>Builder to chain operations.</returns>
public TraceParamsBuilder SetMaxNumberOfMessageEvents(int maxNumberOfMessageEvents)
{
this.maxNumberOfMessageEvents = maxNumberOfMessageEvents;
return this;
}
/// <summary>
/// Sets the maximum number of links on span.
/// </summary>
/// <param name="maxNumberOfLinks">Maximum number of links on span.</param>
/// <returns>Builder to chain operations.</returns>
public TraceParamsBuilder SetMaxNumberOfLinks(int maxNumberOfLinks)
{
this.maxNumberOfLinks = maxNumberOfLinks;
return this;
}
/// <summary>
/// Builds trace parameters from provided arguments.
/// </summary>
/// <returns>Builder to chain operations.</returns>
public TraceParams Build()
{
string missing = string.Empty;
if (this.sampler == null)
{
missing += " sampler";
}
if (!this.maxNumberOfAttributes.HasValue)
{
missing += " maxNumberOfAttributes";
}
if (!this.maxNumberOfAnnotations.HasValue)
{
missing += " maxNumberOfAnnotations";
}
if (!this.maxNumberOfMessageEvents.HasValue)
{
missing += " maxNumberOfMessageEvents";
}
if (!this.maxNumberOfLinks.HasValue)
{
missing += " maxNumberOfLinks";
}
if (!string.IsNullOrEmpty(missing))
{
throw new ArgumentOutOfRangeException("Missing required properties:" + missing);
}
return new TraceParams(
this.sampler,
this.maxNumberOfAttributes.Value,
this.maxNumberOfAnnotations.Value,
this.maxNumberOfMessageEvents.Value,
this.maxNumberOfLinks.Value);
}
}
}

View File

@ -0,0 +1,95 @@
// <copyright file="EndSpanOptions.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace
{
/// <summary>
/// End span options.
/// </summary>
public class EndSpanOptions
{
/// <summary>
/// Default span completion options.
/// </summary>
public static readonly EndSpanOptions Default = new EndSpanOptions(false);
internal EndSpanOptions()
{
}
internal EndSpanOptions(bool sampleToLocalSpanStore, Status status = null)
{
this.SampleToLocalSpanStore = sampleToLocalSpanStore;
this.Status = status;
}
/// <summary>
/// Gets a value indicating whether span needs to be stored into local store.
/// </summary>
public bool SampleToLocalSpanStore { get; }
/// <summary>
/// Gets the span status.
/// </summary>
public Status Status { get; }
/// <summary>
/// Gets the span builder.
/// </summary>
/// <returns>Returns builder to build span options.</returns>
public static EndSpanOptionsBuilder Builder()
{
return new EndSpanOptionsBuilder().SetSampleToLocalSpanStore(false);
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj == this)
{
return true;
}
if (obj is EndSpanOptions that)
{
return (this.SampleToLocalSpanStore == that.SampleToLocalSpanStore)
&& ((this.Status == null) ? (that.Status == null) : this.Status.Equals(that.Status));
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
int h = 1;
h *= 1000003;
h ^= this.SampleToLocalSpanStore ? 1231 : 1237;
h *= 1000003;
h ^= (this.Status == null) ? 0 : this.Status.GetHashCode();
return h;
}
/// <inheritdoc/>
public override string ToString()
{
return "EndSpanOptions{"
+ "sampleToLocalSpanStore=" + this.SampleToLocalSpanStore + ", "
+ "status=" + this.Status
+ "}";
}
}
}

View File

@ -0,0 +1,77 @@
// <copyright file="EndSpanOptionsBuilder.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace
{
using System;
/// <summary>
/// End span options builder.
/// </summary>
public class EndSpanOptionsBuilder
{
private bool? sampleToLocalSpanStore;
private Status status;
internal EndSpanOptionsBuilder()
{
}
/// <summary>
/// Indicate whether span is intended for local spans store.
/// </summary>
/// <param name="sampleToLocalSpanStore">Value indicating whether span is intended for local span store.</param>
/// <returns>Span options builder for operations chaining.</returns>
public EndSpanOptionsBuilder SetSampleToLocalSpanStore(bool sampleToLocalSpanStore)
{
this.sampleToLocalSpanStore = sampleToLocalSpanStore;
return this;
}
/// <summary>
/// Sets the span status.
/// </summary>
/// <param name="status">Span status.</param>
/// <returns>Span options builder for the operations chaining.</returns>
public EndSpanOptionsBuilder SetStatus(Status status)
{
this.status = status;
return this;
}
/// <summary>
/// Builds the span options.
/// </summary>
/// <returns>Span options instance.</returns>
public EndSpanOptions Build()
{
string missing = string.Empty;
if (!this.sampleToLocalSpanStore.HasValue)
{
missing += " sampleToLocalSpanStore";
}
if (!string.IsNullOrEmpty(missing))
{
throw new ArgumentOutOfRangeException("Missing required properties:" + missing);
}
return new EndSpanOptions(
this.sampleToLocalSpanStore.Value,
this.status);
}
}
}

View File

@ -0,0 +1,84 @@
// <copyright file="Attributes.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
public sealed class Attributes : IAttributes
{
internal Attributes(IDictionary<string, IAttributeValue> attributeMap, int droppedAttributesCount)
{
this.AttributeMap = attributeMap ?? throw new ArgumentNullException("Null attributeMap");
this.DroppedAttributesCount = droppedAttributesCount;
}
public IDictionary<string, IAttributeValue> AttributeMap { get; }
public int DroppedAttributesCount { get; }
public static Attributes Create(IDictionary<string, IAttributeValue> attributeMap, int droppedAttributesCount)
{
if (attributeMap == null)
{
throw new ArgumentNullException(nameof(attributeMap));
}
IDictionary<string, IAttributeValue> copy = new Dictionary<string, IAttributeValue>(attributeMap);
return new Attributes(new ReadOnlyDictionary<string, IAttributeValue>(copy), droppedAttributesCount);
}
/// <inheritdoc/>
public override string ToString()
{
return "Attributes{"
+ "attributeMap=" + this.AttributeMap + ", "
+ "droppedAttributesCount=" + this.DroppedAttributesCount
+ "}";
}
/// <inheritdoc/>
public override bool Equals(object o)
{
if (o == this)
{
return true;
}
if (o is Attributes that)
{
return this.AttributeMap.SequenceEqual(that.AttributeMap)
&& (this.DroppedAttributesCount == that.DroppedAttributesCount);
}
return false;
}
/// <inheritdoc/>
public override int GetHashCode()
{
int h = 1;
h *= 1000003;
h ^= this.AttributeMap.GetHashCode();
h *= 1000003;
h ^= this.DroppedAttributesCount;
return h;
}
}
}

View File

@ -0,0 +1,36 @@
// <copyright file="IAttributes.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Attributes collection.
/// </summary>
public interface IAttributes
{
/// <summary>
/// Gets tha dictionaty of attributes by name.
/// </summary>
IDictionary<string, IAttributeValue> AttributeMap { get; }
/// <summary>
/// Gets the number of attributed dropped due to the limit.
/// </summary>
int DroppedAttributesCount { get; }
}
}

View File

@ -0,0 +1,39 @@
// <copyright file="IExportComponent.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
/// <summary>
/// Component that exports spans.
/// </summary>
public interface IExportComponent
{
/// <summary>
/// Gets the span exoprter.
/// </summary>
ISpanExporter SpanExporter { get; }
/// <summary>
/// Gets the running span store.
/// </summary>
IRunningSpanStore RunningSpanStore { get; }
/// <summary>
/// Gets the sampled span store.
/// </summary>
ISampledSpanStore SampledSpanStore { get; }
}
}

View File

@ -0,0 +1,34 @@
// <copyright file="IHandler.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
using System.Threading.Tasks;
/// <summary>
/// Exporter handler.
/// </summary>
public interface IHandler
{
/// <summary>
/// Exports the list of spans to the backend.
/// </summary>
/// <param name="spanDataList">Collection of spans to export.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous export operation.</returns>
Task ExportAsync(IEnumerable<ISpanData> spanDataList);
}
}

View File

@ -0,0 +1,36 @@
// <copyright file="ILinks.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Collection of links.
/// </summary>
public interface ILinks
{
/// <summary>
/// Gets the list of links.
/// </summary>
IEnumerable<ILink> Links { get; }
/// <summary>
/// Gets the number of dropped links due to exceeding the maximum links count limit.
/// </summary>
int DroppedLinksCount { get; }
}
}

View File

@ -0,0 +1,29 @@
// <copyright file="IRunningPerSpanNameSummary.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
/// <summary>
/// Running spans summary.
/// </summary>
public interface IRunningPerSpanNameSummary
{
/// <summary>
/// Gets the number of the running span.
/// </summary>
int NumRunningSpans { get; }
}
}

View File

@ -0,0 +1,50 @@
// <copyright file="IRunningSpanStore.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Running spans store.
/// </summary>
public interface IRunningSpanStore
{
/// <summary>
/// Gets the summary of this store.
/// </summary>
IRunningSpanStoreSummary Summary { get; }
/// <summary>
/// Gets the list of all running spans with the applied filter.
/// </summary>
/// <param name="filter">Filter to apply to query running spans.</param>
/// <returns>List of currently running spans.</returns>
IEnumerable<ISpanData> GetRunningSpans(IRunningSpanStoreFilter filter);
/// <summary>
/// Called when span got started.
/// </summary>
/// <param name="span">Span that was just started.</param>
void OnStart(ISpan span);
/// <summary>
/// Called when span just ended.
/// </summary>
/// <param name="span">Span that just ended.</param>
void OnEnd(ISpan span);
}
}

View File

@ -0,0 +1,34 @@
// <copyright file="IRunningSpanStoreFilter.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
/// <summary>
/// Filter to query spans from the running spans store.
/// </summary>
public interface IRunningSpanStoreFilter
{
/// <summary>
/// Gets the name of the span to query.
/// </summary>
string SpanName { get; }
/// <summary>
/// Gets the maximum number of spans to return.
/// </summary>
int MaxSpansToReturn { get; }
}
}

View File

@ -0,0 +1,31 @@
// <copyright file="IRunningSpanStoreSummary.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Summary of all running spans.
/// </summary>
public interface IRunningSpanStoreSummary
{
/// <summary>
/// Gets the summary of running spans per span name.
/// </summary>
IDictionary<string, IRunningPerSpanNameSummary> PerSpanNameSummary { get; }
}
}

View File

@ -0,0 +1,36 @@
// <copyright file="ISampledLatencyBucketBoundaries.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System;
/// <summary>
/// Sampoled spans latency buckets for histograms calculations.
/// </summary>
public interface ISampledLatencyBucketBoundaries
{
/// <summary>
/// Gets the lower latency boundary.
/// </summary>
TimeSpan LatencyLower { get; }
/// <summary>
/// Gets the upper latency boundary.
/// </summary>
TimeSpan LatencyUpper { get; }
}
}

View File

@ -0,0 +1,36 @@
// <copyright file="ISampledPerSpanNameSummary.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Summary of sampled spans.
/// </summary>
public interface ISampledPerSpanNameSummary
{
/// <summary>
/// Gets the number of sampled spans by latency boundary.
/// </summary>
IDictionary<ISampledLatencyBucketBoundaries, int> NumbersOfLatencySampledSpans { get; }
/// <summary>
/// Gets the number of error sampled spans by error code.
/// </summary>
IDictionary<CanonicalCode, int> NumbersOfErrorSampledSpans { get; }
}
}

View File

@ -0,0 +1,68 @@
// <copyright file="ISampledSpanStore.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Samples spans store.
/// </summary>
public interface ISampledSpanStore
{
/// <summary>
/// Gets the summary of sampled spans.
/// </summary>
ISampledSpanStoreSummary Summary { get; }
/// <summary>
/// Gets all registered span names.
/// </summary>
ISet<string> RegisteredSpanNamesForCollection { get; }
/// <summary>
/// Gets the list of sampled spans using the provided filter.
/// </summary>
/// <param name="filter">Filter to use to query sampled store.</param>
/// <returns>List of spans satisfying filtering criteria.</returns>
IEnumerable<ISpanData> GetLatencySampledSpans(ISampledSpanStoreLatencyFilter filter);
/// <summary>
/// Gets the list of error spans using provided error filter.
/// </summary>
/// <param name="filter">Filter to use to query store.</param>
/// <returns>List of sampled spans satisfying filtering criteria.</returns>
IEnumerable<ISpanData> GetErrorSampledSpans(ISampledSpanStoreErrorFilter filter);
/// <summary>
/// Registers span names for collection.
/// </summary>
/// <param name="spanNames">List of span names.</param>
void RegisterSpanNamesForCollection(IEnumerable<string> spanNames);
/// <summary>
/// Unregister span names for the collection.
/// </summary>
/// <param name="spanNames">Span names to unregister.</param>
void UnregisterSpanNamesForCollection(IEnumerable<string> spanNames);
/// <summary>
/// Consider span for sampling.
/// </summary>
/// <param name="span">Span to consider.</param>
void ConsiderForSampling(ISpan span);
}
}

View File

@ -0,0 +1,39 @@
// <copyright file="ISampledSpanStoreErrorFilter.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
/// <summary>
/// Sampled spans store error filter.
/// </summary>
public interface ISampledSpanStoreErrorFilter
{
/// <summary>
/// Gets the span name to use to filter.
/// </summary>
string SpanName { get; }
/// <summary>
/// Gets the cannonical code to use to filter.
/// </summary>
CanonicalCode? CanonicalCode { get; }
/// <summary>
/// Gets the maximum number of spans to return.
/// </summary>
int MaxSpansToReturn { get; }
}
}

View File

@ -0,0 +1,46 @@
// <copyright file="ISampledSpanStoreLatencyFilter.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System;
/// <summary>
/// Sampled span store latency filter.
/// </summary>
public interface ISampledSpanStoreLatencyFilter
{
/// <summary>
/// Gets the span name to filter by.
/// </summary>
string SpanName { get; }
/// <summary>
/// Gets the latency lower boundery to filter by.
/// </summary>
TimeSpan LatencyLower { get; }
/// <summary>
/// Gets the latency upper boundary to filter by.
/// </summary>
TimeSpan LatencyUpper { get; }
/// <summary>
/// Gets the maximum number of spans to return.
/// </summary>
int MaxSpansToReturn { get; }
}
}

View File

@ -0,0 +1,31 @@
// <copyright file="ISampledSpanStoreSummary.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System.Collections.Generic;
/// <summary>
/// Summary of sampled spans store.
/// </summary>
public interface ISampledSpanStoreSummary
{
/// <summary>
/// Gets the collection of summaries by span name.
/// </summary>
IDictionary<string, ISampledPerSpanNameSummary> PerSpanNameSummary { get; }
}
}

View File

@ -0,0 +1,91 @@
// <copyright file="ISpanData.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using OpenCensus.Common;
/// <summary>
/// Span data with read-only properties.
/// </summary>
public interface ISpanData
{
/// <summary>
/// Gets the span context.
/// </summary>
ISpanContext Context { get; }
/// <summary>
/// Gets the parent span id.
/// </summary>
ISpanId ParentSpanId { get; }
/// <summary>
/// Gets a value indicating whether span has a remote parent.
/// </summary>
bool? HasRemoteParent { get; }
/// <summary>
/// Gets the span name.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the start timestamp.
/// </summary>
Timestamp StartTimestamp { get; }
/// <summary>
/// Gets the collection of attributes.
/// </summary>
IAttributes Attributes { get; }
/// <summary>
/// Gets the collection of annotations.
/// </summary>
ITimedEvents<IAnnotation> Annotations { get; }
/// <summary>
/// Gets the collection of message events.
/// </summary>
ITimedEvents<IMessageEvent> MessageEvents { get; }
/// <summary>
/// Gets the links collection.
/// </summary>
ILinks Links { get; }
/// <summary>
/// Gets the childer span count.
/// </summary>
int? ChildSpanCount { get; }
/// <summary>
/// Gets the span result status.
/// </summary>
Status Status { get; }
/// <summary>
/// Gets the span kind.
/// </summary>
SpanKind Kind { get; }
/// <summary>
/// Gets the end timestamp.
/// </summary>
Timestamp EndTimestamp { get; }
}
}

View File

@ -0,0 +1,58 @@
// <copyright file="ISpanExporter.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Span exporter.
/// </summary>
public interface ISpanExporter : IDisposable
{
/// <summary>
/// Adds a single span to the exporter.
/// </summary>
/// <param name="span">Span to export.</param>
void AddSpan(ISpan span);
/// <summary>
/// Exports collection of spans. This method is used for the situation when the
/// span objects have been created from external sources, not using the Open Censis API.
/// For example, read from file or generated from objects recieved in async queue.
/// </summary>
/// <param name="export">Set of <see cref="ISpanData"/> objects to export.</param>
/// <param name="token">Cancellation token.</param>
/// <returns>A <see cref="Task"/> representing asynchronous export operation.</returns>
Task ExportAsync(IEnumerable<ISpanData> export, CancellationToken token);
/// <summary>
/// Registers the exporter handler.
/// </summary>
/// <param name="name">Name of the handler.</param>
/// <param name="handler">Handler instance.</param>
void RegisterHandler(string name, IHandler handler);
/// <summary>
/// Unregister handler by it's name.
/// </summary>
/// <param name="name">Name of the handler to unregister.</param>
void UnregisterHandler(string name);
}
}

View File

@ -0,0 +1,37 @@
// <copyright file="ITimedEvent.cs" company="OpenCensus Authors">
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenCensus.Trace.Export
{
using OpenCensus.Common;
/// <summary>
/// Timed event.
/// </summary>
/// <typeparam name="T">Type of the timed event.</typeparam>
public interface ITimedEvent<T>
{
/// <summary>
/// Gets the timestamp associated with this timed event.
/// </summary>
Timestamp Timestamp { get; }
/// <summary>
/// Gets the typed event content.
/// </summary>
T Event { get; }
}
}

Some files were not shown because too many files have changed in this diff Show More